【问题标题】:Try return value of product in sale order line for Odoo10尝试 Odoo10 销售订单行中产品的返回值
【发布时间】:2017-10-26 06:31:18
【问题描述】:

我在基于 product.product 的销售订单中有一个 Many2one('product_weight') 字段。我尝试在销售订单行(产品)中返回该字段值。在 product.template 我添加了一个复选框('is_weight')。因此,在“product_weight”的销售订单中,只有重量产品可用。那么,如何在销售订单行(product_id)中返回“product_weight”值?

我的代码在这里:

class sale_order_pet(models.Model):

    _inherit = "sale.order"

 product_weight = fields.Many2one('product.product', string='Service products', domain="[('is_weight','=',True)]")



    @api.onchange('product_id')

    def _onchange_action_weight_add(self):

        res = self.product_id

        print"resss:::", res

        if res:

            line_values = {'product_id': self.product_weight.id,

                           }

            sale_order_line = self.env['sale.order.line'].create(line_values)

提前致谢

【问题讨论】:

  • 您想在销售订单行中显示产品重量吗?
  • 是的,我想在 product_id(销售订单行)中显示 product_weight
  • @PAWANSHARMA 您不能在 onchange 中创建记录,如果您只想显示 check_box('is_weight') 的产品,那么只需找到所有产品 ID 并返回类似的域。 [('id', 'in', ids)]]
  • 你好@Heroic,我已经用域过滤了我的product_weight。但是,问题与 onchange 功能有关。如何在product_weight上应用onchange,选择Product_weight后自动填写销售订单行(product_id)?
  • @PAWANSHARMA 所以可以将其添加到订单中。 self.order_line = [(0,0,{'product_id': self.product_weight.id})]

标签: python-2.7 odoo-10


【解决方案1】:

您可以使用此代码:

    @api.onchange('product_weight ')

    def _onchange_action_weight_add(self):

        res = self.product_id

        print"resss:::", res

        if res:

            line_values = {
                  'order_id': self.id,
                  'product_id': self.product_weight.id,

                           }

            sale_order_line = self.env['sale.order.line'].create(line_values)

【讨论】:

  • 你好 Karara,我在终端上没有打印任何 id。还有一个想法是告诉我,我在哪里调用这个 onchange 函数,因为它应该在销售订单行返回。所以,我们在销售订单行上调用这个 onchange 函数。谢谢卡拉拉...!!
  • 您在销售订单中使用此更改
  • 是的,我应用了,但销售订单行中没有返回值
  • 您需要添加 'name' 'product_uom_qty' 'product_uom' 'price_unit'
  • 是的,已经添加了,这里是:@api.multi def _prepare_productpack_order_line_procurement(self, pack, group_id=False): self.ensure_one() date_planned = datetime.strptime(self.order_id.date_order , DEFAULT_SERVER_DATETIME_FORMAT)\ + timedelta(days=self.customer_lead or 0.0) - timedelta(days=self.order_id.company_id.security_lead) return { 'name': pack.name, 'origin': self.order_id.name, 'product_id ':pack.id,'product_qty':self.product_uom_qty,'product_uom':pack.uom_id.id,}
【解决方案2】:

试试这个:

sale_order_line.py

class sale_order_line(models.Model):

_inherit = "sale.order.line"

product_weight = fields.Float('重量',

related='product_id.weight',

digits=dp.get_precision('产品重量'),

help="内容物重量Kg,不包括任何包装, 等等”)

而对于 xml 你可以继承 sale.view_order_form:

sale_order_views.xml

<record id="view_weight_order_form" model="ir.ui.view">
            <field name="name">sale.order.form</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <xpath expr="//field[@name='order_line']/tree/field[@name='product_id']"
                  position="after">
                    <field name="product_weight "/>
                </xpath>
            </field>
        </record>

希望对你有帮助...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多