Skip to content

Commit

Permalink
[13.0] [FIX] account_payment_group_document: Set the name of the paym…
Browse files Browse the repository at this point in the history
…ent group without receiptbook.
  • Loading branch information
nicomacr committed Sep 29, 2020
1 parent 4a172fb commit ccaef4b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions account_payment_group_document/models/account_payment_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class AccountPaymentGroup(models.Model):
)
document_number = fields.Char(
compute='_compute_document_number', inverse='_inverse_document_number',
string='Document Number', readonly=True, states={'draft': [('readonly', False)]})
string='Document Number', readonly=True,
states={'draft': [('readonly', False)]})

_sql_constraints = [
('name_uniq', 'unique(name, receiptbook_id)',
Expand All @@ -65,10 +66,12 @@ def _inverse_document_number(self):
if not rec.document_number:
rec.name = False
else:
document_number = rec.document_type_id._format_document_number(rec.document_number)
document_number = rec.document_type_id._format_document_number(
rec.document_number)
if rec.document_number != document_number:
rec.document_number = document_number
rec.name = "%s %s" % (rec.document_type_id.doc_code_prefix, document_number)
rec.name = "%s %s" % (
rec.document_type_id.doc_code_prefix, document_number)

@api.depends(
'receiptbook_id.sequence_id.number_next_actual',
Expand Down Expand Up @@ -120,14 +123,15 @@ def _get_receiptbook(self):
def post(self):
for rec in self:
if not rec.document_number:
if not rec.receiptbook_id.sequence_id:
if rec.receiptbook_id and not rec.receiptbook_id.sequence_id:
raise UserError(_(
'Error!. Please define sequence on the receiptbook'
' related documents to this payment or set the '
'document number.'))
rec.document_number = (
rec.receiptbook_id.with_context(
ir_sequence_date=rec.payment_date
if rec.receiptbook_id.sequence_id:
rec.document_number = (
rec.receiptbook_id.with_context(
ir_sequence_date=rec.payment_date
).sequence_id.next_by_id())
rec.payment_ids.move_name = rec.name

Expand All @@ -137,6 +141,10 @@ def post(self):
# necesitamos realmente mandar el tipo de documento? lo necesitamos para algo?
super(AccountPaymentGroup, self.with_context(
default_l10n_latam_document_type_id=rec.document_type_id.id)).post()
if not rec.receiptbook_id:
rec.name = any(
rec.payment_ids.mapped('name')) and ', '.join(
rec.payment_ids.mapped('name')) or False

for rec in self:
if rec.receiptbook_id.mail_template_id:
Expand Down

0 comments on commit ccaef4b

Please sign in to comment.