diff --git a/l10n_ar_sale/models/sale_order.py b/l10n_ar_sale/models/sale_order.py index 5f19497..969fea5 100644 --- a/l10n_ar_sale/models/sale_order.py +++ b/l10n_ar_sale/models/sale_order.py @@ -61,13 +61,21 @@ def _get_sale_checkbook(self): @api.model_create_multi def create(self, vals): for val in vals: + sale_checkbook_id = val.get('sale_checkbook_id') + sale_checkbook_type = val.get('type_id') if self.env.user.has_group('l10n_ar_sale.use_sale_checkbook') and \ val.get('name', _('New')) == _('New') and \ - val.get('sale_checkbook_id'): + sale_checkbook_id: sale_checkbook = self.env['sale.checkbook'].browse( - val.get('sale_checkbook_id')) + sale_checkbook_id) val['name'] = sale_checkbook.sequence_id and\ sale_checkbook.sequence_id._next() or _('New') + elif sale_checkbook_type and not sale_checkbook_id: + sale_checkbook_from_type = self.env['sale.order.type'].browse(sale_checkbook_type).sale_checkbook_id + # Obtenemos el talonario asociado al tipo de venta, esto lo utilizamos si la venta viene de website + # O el usuario no tiene acceso a los talonarios de venta + val['name'] = sale_checkbook_from_type and sale_checkbook_from_type.sequence_id and\ + sale_checkbook_from_type.sequence_id._next() or _('New') return super(SaleOrder, self).create(vals) def write(self, vals):