[IMP] sale: fix action_view_invoice in batch
action_view_invoice is made to work on empty/single/multi records, but there are context keys used to provide defaults when creating invoices in the next view. However when those fields are different among the origin sale orders, we get an error, because the record set's values is accessed like in a single record. In this record we add the default_* context keys only if the recordset is of length 1, so it keep working as before for single/no records. And it doesn't crash when coming from multiple sale orders with different fields. related task 2047389
This commit is contained in:
@@ -490,14 +490,19 @@ class SaleOrder(models.Model):
|
||||
action['res_id'] = invoices.id
|
||||
else:
|
||||
action = {'type': 'ir.actions.act_window_close'}
|
||||
action['context'] = {
|
||||
|
||||
context = {
|
||||
'default_type': 'out_invoice',
|
||||
'default_partner_id': self.partner_id.id,
|
||||
'default_partner_shipping_id': self.partner_shipping_id.id,
|
||||
'default_invoice_payment_term_id': self.payment_term_id.id,
|
||||
'default_invoice_origin': self.name,
|
||||
'default_user_id': self.user_id.id,
|
||||
}
|
||||
if len(self) == 1:
|
||||
context.update({
|
||||
'default_partner_id': self.partner_id.id,
|
||||
'default_partner_shipping_id': self.partner_shipping_id.id,
|
||||
'default_invoice_payment_term_id': self.payment_term_id.id,
|
||||
'default_invoice_origin': self.mapped('name'),
|
||||
'default_user_id': self.user_id.id,
|
||||
})
|
||||
action['context'] = context
|
||||
return action
|
||||
|
||||
def _create_invoices(self, grouped=False, final=False):
|
||||
@@ -696,7 +701,7 @@ class SaleOrder(models.Model):
|
||||
|
||||
def _get_forbidden_state_confirm(self):
|
||||
return {'done', 'cancel'}
|
||||
|
||||
|
||||
def _prepare_analytic_account_data(self, prefix=None):
|
||||
"""
|
||||
Prepare method for analytic account data
|
||||
|
||||
Reference in New Issue
Block a user