summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorqdp-odoo <qdp@odoo.com>2017-08-30 09:16:47 +0200
committerqdp-odoo <qdp@odoo.com>2017-08-30 09:16:47 +0200
commitb2f2006b7fc2c7301e048df7e392193f56aecd79 (patch)
treefd3fcecc96eb8aaac2d2e6090704b5d204a4e726 /addons
parent122242233358ad95d40a3e65229b65684fa3222c (diff)
[FIX] account: sequence_number_next fixes.
-changing the date_invoice field do not reset anymore the sequence_number_next (it now only affects the prefix) -the date_invoice is now passed as ir_sequence_date AND ir_sequence_date_range in the context, for sequences that use the date_range feature in prefixes
Diffstat (limited to 'addons')
-rw-r--r--addons/account/models/account_invoice.py45
1 files changed, 30 insertions, 15 deletions
diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index 3ad85d3cfa2..1bcf86010aa 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -343,38 +343,53 @@ class AccountInvoice(models.Model):
has_outstanding = fields.Boolean(compute='_get_outstanding_info_JSON', groups="account.group_account_invoice")
#fields use to set the sequence, on the first invoice of the journal
- sequence_number_next = fields.Char(string='Next Number', compute="_get_sequence_prefix", inverse="_set_sequence_next")
+ sequence_number_next = fields.Char(string='Next Number', compute="_get_sequence_number_next", inverse="_set_sequence_next")
sequence_number_next_prefix = fields.Char(string='Next Number', compute="_get_sequence_prefix")
_sql_constraints = [
('number_uniq', 'unique(number, company_id, journal_id, type)', 'Invoice Number must be unique per Company!'),
]
+ def _get_seq_number_next_stuff(self):
+ self.ensure_one()
+ journal_sequence = self.journal_id.sequence_id
+ if self.journal_id.refund_sequence:
+ domain = [('type', '=', self.type)]
+ journal_sequence = self.type in ['in_refund', 'out_refund'] and self.journal_id.refund_sequence_id or self.journal_id.sequence_id
+ elif self.type in ['in_invoice', 'in_refund']:
+ domain = [('type', 'in', ['in_invoice', 'in_refund'])]
+ else:
+ domain = [('type', 'in', ['out_invoice', 'out_refund'])]
+ if self.id:
+ domain += [('id', '<>', self.id)]
+ domain += [('journal_id', '=', self.journal_id.id), ('state', 'not in', ['draft', 'cancel'])]
+ return journal_sequence, domain
+
@api.depends('state', 'journal_id', 'date_invoice')
def _get_sequence_prefix(self):
- """ computes the number that will be assigned to the first invoice/bill/refund of a journal, in order to
+ """ computes the prefix of the number that will be assigned to the first invoice/bill/refund of a journal, in order to
let the user manually change it.
"""
for invoice in self:
- journal_sequence = invoice.journal_id.sequence_id
- if invoice.journal_id.refund_sequence:
- domain = [('type', '=', invoice.type)]
- journal_sequence = invoice.type in ['in_refund', 'out_refund'] and invoice.journal_id.refund_sequence_id or invoice.journal_id.sequence_id
- elif invoice.type in ['in_invoice', 'in_refund']:
- domain = [('type', 'in', ['in_invoice', 'in_refund'])]
+ journal_sequence, domain = invoice._get_seq_number_next_stuff()
+ if (invoice.state == 'draft') and not self.search(domain, limit=1):
+ prefix, dummy = journal_sequence.with_context(ir_sequence_date=invoice.date_invoice,
+ ir_sequence_date_range=invoice.date_invoice)._get_prefix_suffix()
+ invoice.sequence_number_next_prefix = prefix
else:
- domain = [('type', 'in', ['out_invoice', 'out_refund'])]
- if invoice.id:
- domain += [('id', '<>', invoice.id)]
- domain += [('journal_id', '=', invoice.journal_id.id), ('state', 'not in', ['draft', 'cancel'])]
+ invoice.sequence_number_next_prefix = False
+ @api.depends('state', 'journal_id')
+ def _get_sequence_number_next(self):
+ """ computes the number that will be assigned to the first invoice/bill/refund of a journal, in order to
+ let the user manually change it.
+ """
+ for invoice in self:
+ journal_sequence, domain = invoice._get_seq_number_next_stuff()
if (invoice.state == 'draft') and not self.search(domain, limit=1):
- prefix, dummy = journal_sequence.with_context(ir_sequence_date=invoice.date_invoice)._get_prefix_suffix()
- invoice.sequence_number_next_prefix = prefix
number_next = journal_sequence._get_current_sequence().number_next_actual
invoice.sequence_number_next = '%%0%sd' % journal_sequence.padding % number_next
else:
- invoice.sequence_number_next_prefix = False
invoice.sequence_number_next = 'no'
@api.multi