diff --git a/l10n_br_account/models/account_move.py b/l10n_br_account/models/account_move.py index b9ebe11edf38..8b57ddb62915 100644 --- a/l10n_br_account/models/account_move.py +++ b/l10n_br_account/models/account_move.py @@ -115,6 +115,21 @@ class AccountMove(models.Model): compute="_compute_fiscal_operation_type", ) + @api.constrains("fiscal_document_id", "fiscal_operation_id") + def _check_fiscal_operation(self): + for rec in self: + if ( + rec.fiscal_operation_id + and not rec.fiscal_operation_id.create_account_move + ): + raise UserError( + _( + "You cannot create an invoice when the fiscal operation is set " + "to not create account move. You can use this operation to " + "create a fiscal document only from the Fiscal App." + ) + ) + @api.constrains("fiscal_document_id", "document_type_id") def _check_fiscal_document_type(self): for rec in self: diff --git a/l10n_br_account/models/fiscal_operation.py b/l10n_br_account/models/fiscal_operation.py index 722c472e15b0..2720ae25f2e2 100644 --- a/l10n_br_account/models/fiscal_operation.py +++ b/l10n_br_account/models/fiscal_operation.py @@ -39,6 +39,8 @@ class Operation(models.Model): company_dependent=True, ) + create_account_move = fields.Boolean(string="Create Account Move", default=True) + def _change_action_view(self, action): fiscal_op_type = action.get("context") if fiscal_op_type == "out": @@ -51,7 +53,9 @@ def _change_action_view(self, action): # TODO FIXME migrate! journal_type = "TODO" # TYPE2JOURNAL[invoice_type] new_action["context"] = { + "create": False, "move_type": invoice_type, + "default_company_id": self.env.company.id, "default_fiscal_operation_type": self.fiscal_operation_type, "default_fiscal_operation_id": self.id, "journal_type": journal_type, @@ -61,14 +65,17 @@ def _change_action_view(self, action): def action_create_new(self): action = super().action_create_new() - action["res_model"] = "account.move" - action["view_id"] = self.env.ref("l10n_br_account.fiscal_invoice_form").id - action["context"] = self._change_action_view(action)["context"] + if self.create_account_move: + action["res_model"] = "account.move" + action["view_id"] = self.env.ref("l10n_br_account.fiscal_invoice_form").id + action["context"] = self._change_action_view(action)["context"] return action def open_action(self): action = super().open_action() - return self._change_action_view(action) + if self.create_account_move: + return self._change_action_view(action) + return action def _fiscal_document_object(self): return self.env["account.move"] diff --git a/l10n_br_account/views/fiscal_operation_view.xml b/l10n_br_account/views/fiscal_operation_view.xml index 302acf08f404..2ed33bfe4d71 100644 --- a/l10n_br_account/views/fiscal_operation_view.xml +++ b/l10n_br_account/views/fiscal_operation_view.xml @@ -49,6 +49,10 @@ name="deductible_taxes" attrs="{'readonly': [('state', '!=', 'draft')]}" /> + diff --git a/l10n_br_account/views/l10n_br_account_action.xml b/l10n_br_account/views/l10n_br_account_action.xml index 191ee7872951..0ea1e1acf3f0 100644 --- a/l10n_br_account/views/l10n_br_account_action.xml +++ b/l10n_br_account/views/l10n_br_account_action.xml @@ -90,7 +90,7 @@ >[('move_type', 'in', ('in_invoice', 'in_receipt', 'out_refund')), ('fiscal_operation_type', '=', 'in')] {'move_type':'in_invoice', 'journal_type': 'purchase'} + >{'move_type':'in_invoice', 'journal_type': 'purchase', 'create': False} @@ -127,7 +127,7 @@ >[('move_type', 'in', ('out_invoice', 'out_receipt', 'in_refund')), ('fiscal_operation_type', '=', 'out')] {'move_type':'out_invoice', 'journal_type': 'sale', 'default_fiscal_operation_type': 'out'} + >{'move_type':'out_invoice', 'journal_type': 'sale', 'default_fiscal_operation_type': 'out', 'create': False} @@ -172,6 +172,7 @@ tree,kanban,form,pivot,graph,activity + {'create': False} Create a new Document
@@ -127,7 +127,7 @@ >[('move_type', 'in', ('out_invoice', 'out_receipt', 'in_refund')), ('fiscal_operation_type', '=', 'out')]
@@ -172,6 +172,7 @@ tree,kanban,form,pivot,graph,activity + {'create': False} Create a new Document
Create a new Document