2
0

[IMP] account_template_active: black, isort, prettier

This commit is contained in:
Stefan Rijnhart 2021-05-18 11:52:53 +02:00 committed by Sylvain LE GAL
parent f1526dc6c7
commit 4a630e320c
8 changed files with 110 additions and 75 deletions

View File

@ -15,10 +15,12 @@ class AccountAccountTemplate(models.Model):
if "active" in vals and not vals.get("active"): if "active" in vals and not vals.get("active"):
# Disable account.account.template should disable # Disable account.account.template should disable
# account.fiscal.position.account.template associated # account.fiscal.position.account.template associated
fpaTemplates = FpaTemplate.search([ fpaTemplates = FpaTemplate.search(
"|", [
("account_src_id", "in", self.ids), "|",
("account_dest_id", "in", self.ids), ("account_src_id", "in", self.ids),
]) ("account_dest_id", "in", self.ids),
]
)
fpaTemplates.write({"active": False}) fpaTemplates.write({"active": False})
return super().write(vals) return super().write(vals)

View File

@ -16,8 +16,7 @@ class AccountFiscalPositionAccountTemplate(models.Model):
# enable account.fiscal.position.account.template should enable # enable account.fiscal.position.account.template should enable
# related account.account.template # related account.account.template
account_ids = set( account_ids = set(
self.mapped("account_src_id").ids self.mapped("account_src_id").ids + self.mapped("account_dest_id").ids
+ self.mapped("account_dest_id").ids
) )
accountTemplates = AccountTemplate.browse(account_ids) accountTemplates = AccountTemplate.browse(account_ids)
accountTemplates.write({"active": True}) accountTemplates.write({"active": True})

View File

@ -16,8 +16,7 @@ class AccountFiscalPositionTaxTemplate(models.Model):
# enable account.fiscal.position.tax.template should enable # enable account.fiscal.position.tax.template should enable
# related account.tax.template # related account.tax.template
tax_ids = set( tax_ids = set(
self.mapped("tax_src_id").ids self.mapped("tax_src_id").ids + self.mapped("tax_dest_id").ids
+ self.mapped("tax_dest_id").ids
) )
taxTemplates = TaxTemplate.browse(tax_ids) taxTemplates = TaxTemplate.browse(tax_ids)
taxTemplates.write({"active": True}) taxTemplates.write({"active": True})

View File

@ -13,10 +13,12 @@ class AccountTaxTemplate(models.Model):
if "active" in vals and not vals.get("active"): if "active" in vals and not vals.get("active"):
# Disable account.tax.template should disable # Disable account.tax.template should disable
# account.fiscal.position.tax.template associated # account.fiscal.position.tax.template associated
fptTemplates = FptTemplate.search([ fptTemplates = FptTemplate.search(
"|", [
("tax_src_id", "in", self.ids), "|",
("tax_dest_id", "in", self.ids), ("tax_src_id", "in", self.ids),
]) ("tax_dest_id", "in", self.ids),
]
)
fptTemplates.write({"active": False}) fptTemplates.write({"active": False})
return super().write(vals) return super().write(vals)

View File

@ -12,64 +12,82 @@ class TestModule(TransactionCase):
self.AATemplate = self.env["account.account.template"] self.AATemplate = self.env["account.account.template"]
self.ATTemplate = self.env["account.tax.template"] self.ATTemplate = self.env["account.tax.template"]
self.AFPTemplate = self.env["account.fiscal.position.template"] self.AFPTemplate = self.env["account.fiscal.position.template"]
self.AFPATemplate =\ self.AFPATemplate = self.env["account.fiscal.position.account.template"]
self.env["account.fiscal.position.account.template"]
self.AFPTTemplate = self.env["account.fiscal.position.tax.template"] self.AFPTTemplate = self.env["account.fiscal.position.tax.template"]
self.receivable_type = self.env.ref( self.receivable_type = self.env.ref("account.data_account_type_receivable")
"account.data_account_type_receivable")
self.template = self.ACTemplate.create({ self.template = self.ACTemplate.create(
"name": "Chart of Account", {
"bank_account_code_prefix": "BNK", "name": "Chart of Account",
"cash_account_code_prefix": "CSH", "bank_account_code_prefix": "BNK",
"transfer_account_code_prefix": "TRSF", "cash_account_code_prefix": "CSH",
"currency_id": self.env.ref("base.EUR").id, "transfer_account_code_prefix": "TRSF",
}) "currency_id": self.env.ref("base.EUR").id,
}
)
self.account_template = self.AATemplate.create({ self.account_template = self.AATemplate.create(
"name": "Account Template", {
"code": "CODE", "name": "Account Template",
"user_type_id": self.receivable_type.id, "code": "CODE",
"chart_template_id": self.template.id, "user_type_id": self.receivable_type.id,
}) "chart_template_id": self.template.id,
self.tax_template = self.ATTemplate.create({ }
"name": "Tax Template", )
"chart_template_id": self.template.id, self.tax_template = self.ATTemplate.create(
"amount": 10.0, {
}) "name": "Tax Template",
self.fiscal_position = self.AFPTemplate.create({ "chart_template_id": self.template.id,
"name": "Fiscal Position", "amount": 10.0,
"chart_template_id": self.template.id, }
}) )
self.fiscal_position_account = self.AFPATemplate.create({ self.fiscal_position = self.AFPTemplate.create(
"account_src_id": self.account_template.id, {
"account_dest_id": self.account_template.id, "name": "Fiscal Position",
"position_id": self.fiscal_position.id, "chart_template_id": self.template.id,
}) }
self.fiscal_position_tax = self.AFPTTemplate.create({ )
"tax_src_id": self.tax_template.id, self.fiscal_position_account = self.AFPATemplate.create(
"position_id": self.fiscal_position.id, {
}) "account_src_id": self.account_template.id,
"account_dest_id": self.account_template.id,
"position_id": self.fiscal_position.id,
}
)
self.fiscal_position_tax = self.AFPTTemplate.create(
{
"tax_src_id": self.tax_template.id,
"position_id": self.fiscal_position.id,
}
)
def test_tax_template(self): def test_tax_template(self):
self.tax_template.active = False self.tax_template.active = False
self.assertEqual( self.assertEqual(
self.fiscal_position_tax.active, False, self.fiscal_position_tax.active,
"Disable Tax template should disable Fiscal Position Tax") False,
"Disable Tax template should disable Fiscal Position Tax",
)
self.fiscal_position_tax.active = True self.fiscal_position_tax.active = True
self.assertEqual( self.assertEqual(
self.tax_template.active, True, self.tax_template.active,
"Enable Fiscal Position Tax should enable Tax Template") True,
"Enable Fiscal Position Tax should enable Tax Template",
)
def test_account_template(self): def test_account_template(self):
self.account_template.active = False self.account_template.active = False
self.assertEqual( self.assertEqual(
self.fiscal_position_account.active, False, self.fiscal_position_account.active,
"Disable Account template should disable Fiscal Position Account") False,
"Disable Account template should disable Fiscal Position Account",
)
self.fiscal_position_account.active = True self.fiscal_position_account.active = True
self.assertEqual( self.assertEqual(
self.account_template.active, True, self.account_template.active,
"Enable Fiscal Position Account should enable Account Template") True,
"Enable Fiscal Position Account should enable Account Template",
)

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<!-- <!--
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain) @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
@ -15,7 +15,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<attribute name="decoration-muted">not active</attribute> <attribute name="decoration-muted">not active</attribute>
</xpath> </xpath>
<field name="user_type_id" position="after"> <field name="user_type_id" position="after">
<field name="active" widget="boolean_toggle"/> <field name="active" widget="boolean_toggle" />
</field> </field>
</field> </field>
</record> </record>
@ -25,7 +25,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="inherit_id" ref="account.view_account_template_form" /> <field name="inherit_id" ref="account.view_account_template_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="chart_template_id" position="after"> <field name="chart_template_id" position="after">
<field name="active"/> <field name="active" />
</field> </field>
</field> </field>
</record> </record>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<!-- <!--
Copyright (C) 2018 - Today: GRAP (http://www.grap.coop) Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain) @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
@ -15,7 +15,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<attribute name="decoration-muted">not active</attribute> <attribute name="decoration-muted">not active</attribute>
</xpath> </xpath>
<field name="name" position="after"> <field name="name" position="after">
<field name="active" widget="boolean_toggle"/> <field name="active" widget="boolean_toggle" />
</field> </field>
</field> </field>
</record> </record>
@ -25,27 +25,42 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="inherit_id" ref="account.view_account_position_template_form" /> <field name="inherit_id" ref="account.view_account_position_template_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="chart_template_id" position="after"> <field name="chart_template_id" position="after">
<field name="active"/> <field name="active" />
</field> </field>
<xpath expr="//field[@name='tax_ids']/tree" position="attributes"> <xpath expr="//field[@name='tax_ids']/tree" position="attributes">
<attribute name="decoration-muted">not active</attribute> <attribute name="decoration-muted">not active</attribute>
</xpath> </xpath>
<xpath expr="//field[@name='tax_ids']/tree/field[@name='tax_dest_id']" position="after"> <xpath
<field name="active" widget="boolean_toggle"/> expr="//field[@name='tax_ids']/tree/field[@name='tax_dest_id']"
position="after"
>
<field name="active" widget="boolean_toggle" />
</xpath> </xpath>
<xpath expr="//field[@name='tax_ids']/form/field[@name='tax_dest_id']" position="after"> <xpath
<field name="active"/> expr="//field[@name='tax_ids']/form/field[@name='tax_dest_id']"
position="after"
>
<field name="active" />
</xpath> </xpath>
<xpath expr="//field[@name='account_ids']/tree/field[@name='account_dest_id']" position="after"> <xpath
<field name="active" widget="boolean_toggle"/> expr="//field[@name='account_ids']/tree/field[@name='account_dest_id']"
position="after"
>
<field name="active" widget="boolean_toggle" />
</xpath> </xpath>
<xpath expr="//field[@name='account_ids']/form/field[@name='account_dest_id']" position="after"> <xpath
<field name="active"/> expr="//field[@name='account_ids']/form/field[@name='account_dest_id']"
position="after"
>
<field name="active" />
</xpath> </xpath>
</field> </field>
</record> </record>
<record id="account.action_account_fiscal_position_template_form" model="ir.actions.act_window"> <record
id="account.action_account_fiscal_position_template_form"
model="ir.actions.act_window"
>
<field name="context">{"active_test": False}</field> <field name="context">{"active_test": False}</field>
</record> </record>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<!-- <!--
Copyright (C) 2020 - Today: GRAP (http://www.grap.coop) Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain) @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
@ -8,13 +8,13 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<record id="view_account_tax_template_tree" model="ir.ui.view"> <record id="view_account_tax_template_tree" model="ir.ui.view">
<field name="model">account.tax.template</field> <field name="model">account.tax.template</field>
<field name="inherit_id" ref="account.view_account_tax_template_tree"/> <field name="inherit_id" ref="account.view_account_tax_template_tree" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//tree" position="attributes"> <xpath expr="//tree" position="attributes">
<attribute name="decoration-muted">not active</attribute> <attribute name="decoration-muted">not active</attribute>
</xpath> </xpath>
<field name="description" position="after"> <field name="description" position="after">
<field name="active" widget="boolean_toggle"/> <field name="active" widget="boolean_toggle" />
</field> </field>
</field> </field>
</record> </record>