Skip to content

Commit

Permalink
[FIX] l10n_ar_sale_order: Fix para que se setee correctamente la secu…
Browse files Browse the repository at this point in the history
…encia de la orden de venta
  • Loading branch information
mem-adhoc committed Aug 23, 2024
1 parent e8e2fdb commit 372029b
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions l10n_ar_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _compute_vat_discriminated(self):

@api.depends('company_id')
def _compute_sale_checkbook(self):
for rec in self:
for rec in self.filtered(lambda x: not x.sale_checkbook_id):
if self.env.user.has_group('l10n_ar_sale.use_sale_checkbook') and rec.company_id:
rec.sale_checkbook_id = rec._get_sale_checkbook()
else:
Expand All @@ -57,16 +57,43 @@ def _get_sale_checkbook(self):

@api.model_create_multi
def create(self, vals):
""""
En caso de la creacion de una OV totalmente nueva consumimos el numero de la secuencia
"""
for val in vals:
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 = self.env['sale.checkbook'].browse(
val.get('sale_checkbook_id'))
val['name'] = sale_checkbook.sequence_id and\
sale_checkbook.sequence_id._next() or _('New')
val.get('sale_checkbook_id'):
sale_checkbook = self.env['sale.checkbook'].browse(val.get('sale_checkbook_id'))
if val.get('name', _('New')) == _('New'):
val['name'] = sale_checkbook.sequence_id._next()
else:
number_next = sale_checkbook.sequence_id.number_next_actual
val['name'] = sale_checkbook.sequence_id.get_next_char(number_next)
return super(SaleOrder, self).create(vals)

def write(self, vals):
"""A sale checkbook could have a different order sequence, so we could
need to change it accordingly"""
if self.env.user.has_group('l10n_ar_sale.use_sale_checkbook') and vals.get('sale_checkbook_id'):
sale_checkbook = self.env['sale.checkbook'].browse(vals['sale_checkbook_id'])
if sale_checkbook.sequence_id:
for record in self:
if record.sale_checkbook_id != sale_checkbook and record.state in {"draft", "sent"}:
if not record.name or record.name == _('Nuevo'):
record.name = sale_checkbook.sequence_id._next()
else:
number_next = sale_checkbook.sequence_id.number_next_actual
vals['name'] = sale_checkbook.sequence_id.get_next_char(number_next)
return super(SaleOrder, record).write(vals)
return super().write(vals)

def copy(self, default=None):
"""Necesitamos que cuando duplicamos la OV mantenga el sale_checkbook_id"""
default = dict(default or {})
if self.sale_checkbook_id:
default['sale_checkbook_id'] = self.sale_checkbook_id.id
return super().copy(default)

def _compute_tax_totals(self):
""" Mandamos en contexto el invoice_date para calculo de impuesto con partner aliquot
ver módulo l10n_ar_account_withholding. """
Expand Down

0 comments on commit 372029b

Please sign in to comment.