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"):
# Disable account.account.template should disable
# account.fiscal.position.account.template associated
fpaTemplates = FpaTemplate.search([
fpaTemplates = FpaTemplate.search(
[
"|",
("account_src_id", "in", self.ids),
("account_dest_id", "in", self.ids),
])
]
)
fpaTemplates.write({"active": False})
return super().write(vals)

View File

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

View File

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

View File

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

View File

@ -12,64 +12,82 @@ class TestModule(TransactionCase):
self.AATemplate = self.env["account.account.template"]
self.ATTemplate = self.env["account.tax.template"]
self.AFPTemplate = self.env["account.fiscal.position.template"]
self.AFPATemplate =\
self.env["account.fiscal.position.account.template"]
self.AFPATemplate = self.env["account.fiscal.position.account.template"]
self.AFPTTemplate = self.env["account.fiscal.position.tax.template"]
self.receivable_type = self.env.ref(
"account.data_account_type_receivable")
self.receivable_type = self.env.ref("account.data_account_type_receivable")
self.template = self.ACTemplate.create({
self.template = self.ACTemplate.create(
{
"name": "Chart of Account",
"bank_account_code_prefix": "BNK",
"cash_account_code_prefix": "CSH",
"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",
"user_type_id": self.receivable_type.id,
"chart_template_id": self.template.id,
})
self.tax_template = self.ATTemplate.create({
}
)
self.tax_template = self.ATTemplate.create(
{
"name": "Tax Template",
"chart_template_id": self.template.id,
"amount": 10.0,
})
self.fiscal_position = self.AFPTemplate.create({
}
)
self.fiscal_position = self.AFPTemplate.create(
{
"name": "Fiscal Position",
"chart_template_id": self.template.id,
})
self.fiscal_position_account = self.AFPATemplate.create({
}
)
self.fiscal_position_account = self.AFPATemplate.create(
{
"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({
}
)
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):
self.tax_template.active = False
self.assertEqual(
self.fiscal_position_tax.active, False,
"Disable Tax template should disable Fiscal Position Tax")
self.fiscal_position_tax.active,
False,
"Disable Tax template should disable Fiscal Position Tax",
)
self.fiscal_position_tax.active = True
self.assertEqual(
self.tax_template.active, True,
"Enable Fiscal Position Tax should enable Tax Template")
self.tax_template.active,
True,
"Enable Fiscal Position Tax should enable Tax Template",
)
def test_account_template(self):
self.account_template.active = False
self.assertEqual(
self.fiscal_position_account.active, False,
"Disable Account template should disable Fiscal Position Account")
self.fiscal_position_account.active,
False,
"Disable Account template should disable Fiscal Position Account",
)
self.fiscal_position_account.active = True
self.assertEqual(
self.account_template.active, True,
"Enable Fiscal Position Account should enable Account Template")
self.account_template.active,
True,
"Enable Fiscal Position Account should enable Account Template",
)

View File

@ -30,22 +30,37 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<xpath expr="//field[@name='tax_ids']/tree" position="attributes">
<attribute name="decoration-muted">not active</attribute>
</xpath>
<xpath expr="//field[@name='tax_ids']/tree/field[@name='tax_dest_id']" position="after">
<xpath
expr="//field[@name='tax_ids']/tree/field[@name='tax_dest_id']"
position="after"
>
<field name="active" widget="boolean_toggle" />
</xpath>
<xpath expr="//field[@name='tax_ids']/form/field[@name='tax_dest_id']" position="after">
<xpath
expr="//field[@name='tax_ids']/form/field[@name='tax_dest_id']"
position="after"
>
<field name="active" />
</xpath>
<xpath expr="//field[@name='account_ids']/tree/field[@name='account_dest_id']" position="after">
<xpath
expr="//field[@name='account_ids']/tree/field[@name='account_dest_id']"
position="after"
>
<field name="active" widget="boolean_toggle" />
</xpath>
<xpath expr="//field[@name='account_ids']/form/field[@name='account_dest_id']" position="after">
<xpath
expr="//field[@name='account_ids']/form/field[@name='account_dest_id']"
position="after"
>
<field name="active" />
</xpath>
</field>
</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>
</record>