Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][RFC][14.0] l10n_br_fiscal/l10n_br_account: refactor to prevent potential incorret entries #3536

Draft
wants to merge 5 commits into
base: 14.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions l10n_br_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# data
"data/account_tax_group.xml",
"data/account_tax_template.xml",
"data/fiscal_operation.xml",
# Views
"views/account_tax_view.xml",
"views/account_tax_template_view.xml",
Expand Down
9 changes: 9 additions & 0 deletions l10n_br_account/data/fiscal_operation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">


<record id="l10n_br_fiscal.fo_manifesto" model="l10n_br_fiscal.operation">
<field name="create_account_move">False</field>
</record>

</odoo>
15 changes: 15 additions & 0 deletions l10n_br_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
43 changes: 29 additions & 14 deletions l10n_br_account/models/fiscal_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Copyright (C) 2019 - TODAY Raphaël Valyi - Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models
from odoo import _, fields, models
from odoo.exceptions import UserError

# from odoo.addons.account.models.account_invoice import TYPE2JOURNAL

Expand Down Expand Up @@ -39,6 +40,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":
Expand All @@ -51,7 +54,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,
Expand All @@ -61,25 +66,35 @@ 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:
raise UserError(
_(
"This is a fiscal operation that generates account move, please "
"create the document through the Account App"
)
)
# 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)
# def open_action(self):
# action = super().open_action()
# if self.create_account_move:
# return self._change_action_view(action)
# return action

def _fiscal_document_object(self):
return self.env["account.move"]
# def _fiscal_document_object(self):
# return self.env["account.move"]

def _line_domain(self, company, partner, product):
domain = super()._line_domain(company=company, partner=partner, product=product)

domain += [
"|",
("fiscal_position_id", "=", partner.property_account_position_id.id),
("fiscal_position_id", "=", False),
]
if self.create_account_move:
domain += [
"|",
("fiscal_position_id", "=", partner.property_account_position_id.id),
("fiscal_position_id", "=", False),
]

return domain
4 changes: 4 additions & 0 deletions l10n_br_account/views/fiscal_operation_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
name="deductible_taxes"
attrs="{'readonly': [('state', '!=', 'draft')]}"
/>
<field
name="create_account_move"
attrs="{'readonly': [('state', '!=', 'draft')]}"
/>
</group>
</group>
</page>
Expand Down
9 changes: 5 additions & 4 deletions l10n_br_account/views/l10n_br_account_action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/>
<field
name="context"
eval="{'default_document_type_id': ref('l10n_br_fiscal.document_55')}"
eval="{'default_document_type_id': ref('l10n_br_fiscal.document_55'), 'create': False}"
/>
<field name="search_view_id" ref="l10n_br_account.fiscal_invoice_search" />
<field name="help" type="html">
Expand Down Expand Up @@ -52,7 +52,7 @@
/>
<field
name="context"
eval="{'default_document_type_id': ref('l10n_br_fiscal.document_SE')}"
eval="{'default_document_type_id': ref('l10n_br_fiscal.document_SE'), 'create': False}"
/>
<field name="search_view_id" ref="l10n_br_account.fiscal_invoice_search" />
<field name="help" type="html">
Expand Down Expand Up @@ -90,7 +90,7 @@
>[('move_type', 'in', ('in_invoice', 'in_receipt', 'out_refund')), ('fiscal_operation_type', '=', 'in')]</field>
<field
name="context"
>{'move_type':'in_invoice', 'journal_type': 'purchase'}</field>
>{'move_type':'in_invoice', 'journal_type': 'purchase', 'create': False}</field>
<field name="search_view_id" ref="l10n_br_account.fiscal_invoice_search" />
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Expand Down Expand Up @@ -127,7 +127,7 @@
>[('move_type', 'in', ('out_invoice', 'out_receipt', 'in_refund')), ('fiscal_operation_type', '=', 'out')]</field>
<field
name="context"
>{'move_type':'out_invoice', 'journal_type': 'sale', 'default_fiscal_operation_type': 'out'}</field>
>{'move_type':'out_invoice', 'journal_type': 'sale', 'default_fiscal_operation_type': 'out', 'create': False}</field>
<field name="search_view_id" ref="l10n_br_account.fiscal_invoice_search" />
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Expand Down Expand Up @@ -172,6 +172,7 @@
<field name="view_mode">tree,kanban,form,pivot,graph,activity</field>
<field eval="False" name="view_id" />
<field name="search_view_id" ref="l10n_br_account.fiscal_invoice_search" />
<field name="context">{'create': False}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new Document
Expand Down
12 changes: 6 additions & 6 deletions l10n_br_account/views/l10n_br_account_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
</record>

<!-- Incomming Documents -->
<record id="l10n_br_fiscal.document_in_menu" model="ir.ui.menu">
<!-- <record id="l10n_br_fiscal.document_in_menu" model="ir.ui.menu">
<field name="action" ref="fiscal_invoice_in_action" />
</record>
</record> -->

<!-- Outgoing Documents -->
<record id="l10n_br_fiscal.document_out_menu" model="ir.ui.menu">
<!-- <record id="l10n_br_fiscal.document_out_menu" model="ir.ui.menu">
<field name="action" ref="fiscal_invoice_out_action" />
</record>
</record> -->

<!-- All Documents -->
<!-- (we keep l10n_br_fiscal.document_all_menu
with l10n_br_fiscal.document object for low level fiscal detail)-->
<menuitem
<!-- <menuitem
id="document_all_menu"
action="fiscal_invoice_all_action"
name="All Documents"
groups="l10n_br_fiscal.group_user,l10n_br_fiscal.group_manager"
parent="l10n_br_fiscal.document_sub_menu"
sequence="25"
/>
/> -->

</odoo>
9 changes: 9 additions & 0 deletions l10n_br_fiscal/models/operation_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ def _get_cancelled_documents(self):
def action_create_new(self):
ctx = self._context.copy()
model = "l10n_br_fiscal.document"
if self.document_type_ids:
ctx.update(
{
"default_document_type_id": self.document_type_ids[
0
].document_type_id.id,
}
)
if self.fiscal_operation_type == "out":
ctx.update(
{
Expand Down Expand Up @@ -154,6 +162,7 @@ def open_action(self):
ctx.update(
{
"default_fiscal_operation_type": fiscal_operation_type,
"create": False,
}
)

Expand Down
10 changes: 10 additions & 0 deletions l10n_br_fiscal/views/document_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,16 @@
</page>
</notebook>
</sheet>
<t t-if="model == 'l10n_br_fiscal.document'">
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" />
<field
name="message_ids"
widget="mail_thread"
options="{'post_refresh': 'recipients', 'open_attachments': True}"
/>
</div>
</t>
</form>
</field>
</record>
Expand Down
9 changes: 7 additions & 2 deletions l10n_br_fiscal/views/l10n_br_fiscal_action.xml
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@
<field name="view_mode">kanban,tree,form</field>
<field name="search_view_id" ref="document_search" />
<field name="view_id" ref="document_tree" />
<field name="context">{'create': False}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new Document
Expand All @@ -616,7 +617,9 @@
<field name="search_view_id" ref="document_search" />
<field name="view_id" ref="document_tree" />
<field name="domain">[('fiscal_operation_type', '=', 'in')]</field>
<field name="context">{'default_fiscal_operation_type': 'in'}</field>
<field
name="context"
>{'default_fiscal_operation_type': 'in', 'create': False}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new Document
Expand All @@ -636,7 +639,9 @@
<field name="search_view_id" ref="document_search" />
<field name="view_id" ref="document_tree" />
<field name="domain">[('fiscal_operation_type', '=', 'out')]</field>
<field name="context">{'default_fiscal_operation_type': 'out'}</field>
<field
name="context"
>{'default_fiscal_operation_type': 'out', 'create': False}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Create a new Document
Expand Down
Loading