Untitled
unknown
plain_text
a year ago
1.6 kB
8
Indexable
@api.model_create_multi
def create(self, vals_list):
new_lines = []
for values in vals_list:
# Use .get() method to avoid KeyError
display_type = values.get('display_type', self.default_get(['display_type']).get('display_type'))
if display_type:
values.update({
'product_id': False,
'price_unit': 0,
'product_uom_qty': 0,
'product_uom': False,
'date_planned': False
})
else:
values.update(self._prepare_add_missing_fields(values))
# Create a new purchase order for each line to avoid grouping
order_vals = {
'partner_id': values.get('partner_id'),
'date_order': values.get('date_order'),
'company_id': values.get('company_id'),
# Add any other necessary fields here if needed
}
new_order = self.env['purchase.order'].create(order_vals)
values['order_id'] = new_order.id
new_line = super(PurchaseOrderLine, self).create([values])
new_lines.extend(new_line)
for line in new_line:
if line.product_id and line.order_id.state == 'purchase':
msg = _("Extra line with %s ") % (line.product_id.display_name,)
line.order_id.message_post(body=msg)
return new_linesEditor is loading...
Leave a Comment