summaryrefslogtreecommitdiff
path: root/addons/l10n_latam_invoice_document
diff options
context:
space:
mode:
authorfw-bot <otis@odoo.com>2020-02-04 16:59:10 +0000
committerJosse Colpaert <jco@odoo.com>2020-02-06 10:02:56 +0000
commit7954594d12b0d801fd3802c66d5c6caa521d2ce2 (patch)
tree487780a90f175dfca232d77ee5b0808928e36e32 /addons/l10n_latam_invoice_document
parentc5e34d77f5d84c1811e29cabdffdd408695d1d2d (diff)
[FW][REF] account: new method _prepare_default_reversal
to be able to inherit these methods to make it easier to add fields in the refund wizard e.g. closes odoo/odoo#44629 X-original-commit: e814374a20de096fd795aec34ab0e3de4977fc85 Signed-off-by: Josse Colpaert <jco@openerp.com>
Diffstat (limited to 'addons/l10n_latam_invoice_document')
-rw-r--r--addons/l10n_latam_invoice_document/models/account_move.py2
-rw-r--r--addons/l10n_latam_invoice_document/wizards/account_move_reversal.py21
-rw-r--r--addons/l10n_latam_invoice_document/wizards/account_move_reversal_view.xml1
3 files changed, 20 insertions, 4 deletions
diff --git a/addons/l10n_latam_invoice_document/models/account_move.py b/addons/l10n_latam_invoice_document/models/account_move.py
index 52b8f960a74..327476726a9 100644
--- a/addons/l10n_latam_invoice_document/models/account_move.py
+++ b/addons/l10n_latam_invoice_document/models/account_move.py
@@ -15,7 +15,7 @@ class AccountMove(models.Model):
l10n_latam_tax_ids = fields.One2many(compute="_compute_l10n_latam_amount_and_taxes", comodel_name='account.move.line')
l10n_latam_available_document_type_ids = fields.Many2many('l10n_latam.document.type', compute='_compute_l10n_latam_available_document_types')
l10n_latam_document_type_id = fields.Many2one(
- 'l10n_latam.document.type', string='Document Type', copy=False, readonly=False, auto_join=True, index=True,
+ 'l10n_latam.document.type', string='Document Type', readonly=False, auto_join=True, index=True,
states={'posted': [('readonly', True)]}, compute='_compute_l10n_latam_document_type', store=True)
l10n_latam_use_documents = fields.Boolean(related='journal_id.l10n_latam_use_documents')
l10n_latam_country_code = fields.Char(
diff --git a/addons/l10n_latam_invoice_document/wizards/account_move_reversal.py b/addons/l10n_latam_invoice_document/wizards/account_move_reversal.py
index 0169859a098..d7b202af62a 100644
--- a/addons/l10n_latam_invoice_document/wizards/account_move_reversal.py
+++ b/addons/l10n_latam_invoice_document/wizards/account_move_reversal.py
@@ -10,6 +10,7 @@ class AccountMoveReversal(models.TransientModel):
l10n_latam_use_documents = fields.Boolean(compute='_compute_document_type')
l10n_latam_document_type_id = fields.Many2one('l10n_latam.document.type', 'Document Type', ondelete='cascade', domain="[('id', 'in', l10n_latam_available_document_type_ids)]", compute='_compute_document_type', readonly=False)
l10n_latam_available_document_type_ids = fields.Many2many('l10n_latam.document.type', compute='_compute_document_type')
+ l10n_latam_document_number = fields.Char(string='Document Number')
@api.model
def _reverse_type_map(self, move_type):
@@ -45,6 +46,20 @@ class AccountMoveReversal(models.TransientModel):
record.l10n_latam_document_type_id = refund.l10n_latam_document_type_id
record.l10n_latam_available_document_type_ids = refund.l10n_latam_available_document_type_ids
- def reverse_moves(self):
- return super(AccountMoveReversal, self.with_context(
- default_l10n_latam_document_type_id=self.l10n_latam_document_type_id.id)).reverse_moves()
+ def _prepare_default_reversal(self, move):
+ """ Set the default document type and number in the new revsersal move taking into account the ones selected in
+ the wizard """
+ res = super()._prepare_default_reversal(move)
+ res.update({
+ 'l10n_latam_document_type_id': self.l10n_latam_document_type_id.id,
+ 'name': self.l10n_latam_document_number,
+ })
+ return res
+
+ @api.onchange('l10n_latam_document_number', 'l10n_latam_document_type_id')
+ def _onchange_l10n_latam_document_number(self):
+ if self.l10n_latam_document_type_id:
+ l10n_latam_document_number = self.l10n_latam_document_type_id._format_document_number(
+ self.l10n_latam_document_number)
+ if self.l10n_latam_document_number != l10n_latam_document_number:
+ self.l10n_latam_document_number = l10n_latam_document_number
diff --git a/addons/l10n_latam_invoice_document/wizards/account_move_reversal_view.xml b/addons/l10n_latam_invoice_document/wizards/account_move_reversal_view.xml
index f2d8b96527a..f8f0e416a1c 100644
--- a/addons/l10n_latam_invoice_document/wizards/account_move_reversal_view.xml
+++ b/addons/l10n_latam_invoice_document/wizards/account_move_reversal_view.xml
@@ -12,6 +12,7 @@
<field name="date" position="before">
<field name="l10n_latam_available_document_type_ids" invisible="1"/>
<field name="l10n_latam_document_type_id" attrs="{'invisible': ['|', ('l10n_latam_use_documents', '=', False), ('refund_method', '=', 'refund')], 'required': [('l10n_latam_use_documents', '=', True), ('refund_method', '!=', 'refund')]}" options="{'no_open': True, 'no_create': True}"/>
+ <field name="l10n_latam_document_number" attrs="{'invisible': ['|', '|', ('l10n_latam_use_documents', '=', False), ('refund_method', '=', 'refund')], 'required': [('l10n_latam_use_documents', '=', True), ('refund_method', '!=', 'refund')]}"/>
</field>
</field>
</record>