我有一个One2many字段:'prod_id
','prod_qty
'。
我想增加产品数量。
另一个One2many中每种产品的总数量
prod = []
for rec in self.sale_wiz_ids:
r = list(filter(lambda product: product['prod_id.id'] == rec.prod_id.id, prod))
self.total_qty1 += rec.prod_qty
from odoo import api, models, fields, _
class SalesWizard(models.TransientModel):
_name = 'sale.wizard.details'
sale_wiz_ids = fields.One2many('sale.wiz.line', 'sale_wiz_line_id', string='IDs')
#sale_wiz_ids1 = fields.One2many('sale.wiz.line', 'sale_wiz_line_id', string='IDs')
partner_id = fields.Many2one('res.partner', string='Customer')
total_qty = fields.Integer("Total Quantity")
total_qty1 = fields.Integer("Total Quantity")
@api.multi
def update(self):
prod_brws = self.env['sale.order'].browse(self._context.get("active_ids"))
for j in self.sale_wiz_ids:
vals = {'product_id': j.prod_id.id, 'name': j.prod_desc, 'product_uom_qty': j.prod_qty}
prod_brws.write({'order_line': [(0, 0, vals)]})
@api.model
def default_get(self, fields_list):
result = super(SalesWizard, self).default_get(fields_list)
prod_brws = self.env['sale.order'].browse(self._context.get("active_ids"))
list = []
for record in prod_brws:
for rec in record.order_line:
list1 = (0, 0, {'prod_id': rec.product_id.id, 'prod_desc': rec.name, 'prod_qty': rec.product_uom_qty})
list.append(list1)
result.update({'sale_wiz_ids': list})
return result
@api.onchange('total_qty')
def total(self):
for record in self:
for rec in record.sale_wiz_ids:
record.total_qty += rec.prod_qty
prod = []
for rec in self.sale_wiz_ids:
r = list(filter(lambda product: product['prod_id.id'] == rec.prod_id.id, prod))
self.total_qty1 += rec.prod_qty
class SaleWizardline(models.TransientModel):
_name = 'sale.wiz.line'
sale_wiz_line_id = fields.Many2one('sale.wizard.details', "ID")
prod_id = fields.Many2one('product.product', 'Product Name')
prod_desc = fields.Char(related='prod_id.default_code', string="Description")
prod_qty = fields.Integer("Quantity")