简体   繁体   中英

How to pass wizard fields ids in sale .order.line for Odoo10

I've inherited the sale.order.line and I've added a wizard ( sale.pack.wizard ) accesible from a button of sale.order form. Besides, I have a field test ( One2many type) in the wizard. Now, I want to get the test field IDs in a method of sale.order.line model. So, how can I do this?

class SaleOrderLine(models.Model):
    _inherit = "sale.order.line"

    @api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id', 'product_id','price_subtotal')
    def _compute_amount(self):
        active_id = self.env.context.get('active_ids', []) or []
        new = self.env['sale.pack.wizard'].browse(active_id)
        #Here i want to show 'test' field id from wizard

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)]")
    test = fields.One2many('product.gold','service',string="Pack Products",change_default=True, default=_onchange_action_product_add )

You cannot achieve your purpose in that way. You have to take into account that there is a scheduled action in Odoo ( AutoVacuum osv_memory objects ) which removes every transient model record each 30 minutes (by default). This means that if you were able to get the wizard test field value, even so, it would only return any value the 30 minutes after the wizard was opened for the first time.

So, what I'd do in your case, is to create a new field in sale.order.line model which stores the info you need of the wizard. Then, I'd create a button in the wizard, and when you click on this button, execute a method which fills in the new sale.order.line field with the info you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM