跳至內容
選單
此問題已被標幟
1 回覆
14605 瀏覽次數

Hello All

I have a One2many field in inventory for product pack. And I want that all fields values of that One2many field should update in fields of One2many field in sales order, row and column wise. So, Anyone can help me.

My Python code is here:

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)

Here in 'wizard' (One2many field table) i want to update all fields (row and column) of 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)

頭像
捨棄
作者 最佳答案

Hello all, Problem Solved.

Here is the function code of problem:

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}

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
4月 20
4270
1
12月 21
6682
1
7月 19
3809
0
10月 17
2840
2
10月 17
4716