1

我在产品包的库存中有一个 One2many 字段。而且我希望该 One2many 字段的所有字段值都应该在销售订单、行和列的 One2many 字段的字段中更新。所以,任何人都可以帮助我。

我的 Python 代码在这里:

class ProductTemplate(models.Model):

    _inherit = "product.template"


 product_pack = fields.One2many('product.pack', 'template_id', string='Product Pack', copy=True)

class ProductDesign(models.Model):

    _description = 'Product Pack'

    _name = "product.pack"

    _rec_name = "product_id"



    check_option = fields.Boolean('#')

    template_id = fields.Many2one('product.template', string='Template', required="True", ondelete='cascade', index=True, copy=True)

    product_id = fields.Many2one('product.product', string='Product', required="True", domain="[('is_pack','=',False)]")

    services = fields.Many2one('gold.service')

    qty = fields.Integer('Quantity', default=1)

在“向导”(One2many 字段表)中,我想更新 product_pack 的所有字段(行和列)

class SalePackWizard(models.TransientModel):

    _name = "sale.pack.wizard"

    _description = "Sale Pack Wizard"


 product_id = fields.Many2one('product.product', string="Product Pack", required=True, domain="[('is_pack','=',True)]")

    wizard = fields.One2many('product.gold','service')


 @api.onchange('product_id')

    def _onchange_product_pack_name(self):

         for w in self.product_id.product_pack:

            for s in w:

                print "s:", s.product_id.name, s.services, s.qty

                r = []

                print"r:", r


class ProductDesign(models.Model):

    _description = 'Product Pack'

    _name = "product.gold"

    _rec_name = "products_ids"



    service= fields.Many2one('product.val', string='Templates', required="True", ondelete='cascade', index=True, copy=True)

    check_box = fields.Boolean('#')

    products_ids = fields.Many2one('product.product', string='Product', required="True", domain="[('is_pack','=',False)]")

    services = fields.Many2one('gold.service')

    qtyy = fields.Integer('Quantity', default=1)
4

1 回答 1

1

问题解决了。

这是问题的功能代码:

wizard = fields.One2many('product.gold','service',change_default=True, default=_onchange_action_product_add)



@api.onchange('product_id')

    def _onchange_action_product_add(self):

        res = self.product_id.product_pack

        r = []

        value = {}

        for var in self.product_id.product_pack:

            print "var:::", var

            for line in self.product_id.product_pack:

                print "line:::", line , line.product_id, line.product_id.name, line.qty, line.services, line.id

                data = {'products_ids': line.product_id.id,

                        'service':var.id, #many2one child field from one2many field

                        'services':line.services,

                        'qtyy': line.qty

                        }

                print "data:", data

                r.append((0, 0, data))

                print "r.append", r.append, r

                #return data

            value.update(wizard=r)

            return {'value': value}
于 2017-10-24T10:09:27.773 回答