Skip to content

Commit

Permalink
[MIG] account_cutoff_accrual_subscription to v17
Browse files Browse the repository at this point in the history
Convert onchange to computed fields
Convert read_group() to _read_group()
  • Loading branch information
alexis-via committed Feb 26, 2024
1 parent 9c3ceaa commit 84ce2f4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion account_cutoff_accrual_subscription/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Account Accrual Subscriptions",
"version": "16.0.1.2.0",
"version": "17.0.1.0.0",
"category": "Accounting",
"license": "AGPL-3",
"summary": "Accrued expenses based on subscriptions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class AccountCutoffAccrualSubscription(models.Model):
)
partner_id = fields.Many2one(
"res.partner",
compute="_compute_partner_id", readonly=False, store=True, precompute=True,
string="Partner",
domain=[("parent_id", "=", False)],
ondelete="restrict",
Expand All @@ -72,6 +73,7 @@ class AccountCutoffAccrualSubscription(models.Model):
help="Minimum amount without taxes over the period",
)
provision_amount = fields.Monetary(
compute='_compute_provision_amount', readonly=False, store=True, precompute=True,
string="Default Provision Amount", currency_field="company_currency_id"
)
account_id = fields.Many2one(
Expand All @@ -84,6 +86,7 @@ class AccountCutoffAccrualSubscription(models.Model):
type_tax_use = fields.Char(compute="_compute_type_tax_use")
tax_ids = fields.Many2many(
"account.tax",
compute="_compute_tax_ids", readonly=False, store=True, precompute=True,
string="Taxes",
domain="[('price_include', '=', False), ('company_id', '=', company_id), "
"('type_tax_use', '=', type_tax_use)]",
Expand Down Expand Up @@ -124,23 +127,26 @@ def check_start_date(self):
),
]

@api.onchange("min_amount")
def min_amount_change(self):
if (
self.company_currency_id.compare_amounts(self.min_amount, 0) > 0
and not self.provision_amount
):
self.provision_amount = self.min_amount
@api.depends("min_amount")
def _compute_provision_amount(self):
for sub in self:
if (
sub.company_currency_id.compare_amounts(sub.min_amount, 0) > 0
and sub.company_currency_id.is_zero(sub.provision_amount)
):
sub.provision_amount = sub.min_amount

@api.onchange("account_id")
def account_id_change(self):
if self.account_id:
self.tax_ids = self.account_id.tax_ids
@api.depends("account_id")
def _compute_tax_ids(self):
for sub in self:
if sub.account_id:
sub.tax_ids = sub.account_id.tax_ids

@api.onchange("partner_type")
def partner_type_change(self):
if self.partner_type != "one":
self.partner_id = False
@api.depends("partner_type")
def _compute_partner_id(self):
for sub in self:
if sub.partner_type != "one":
sub.partner_id = False

def _process_subscription(
self, work, fy_start_date, cutoff_date, common_domain, sign
Expand Down Expand Up @@ -221,32 +227,30 @@ def _process_subscription(
# compute amount
amount = 0
# 1. No start/end dates
no_start_end_res = aml_obj.read_group(
no_start_end_res = aml_obj._read_group(
domain_base
+ [
("date", "<=", end_date),
("date", ">=", start_date),
("start_date", "=", False),
("end_date", "=", False),
],
["balance"],
[],
aggregates=["balance:sum"],
)
amount_no_start_end = (
no_start_end_res and no_start_end_res[0]["balance"] or 0
no_start_end_res and no_start_end_res[0][0] or 0
)
amount += amount_no_start_end * sign
# 2. Start/end dates, INSIDE interval
inside_res = aml_obj.read_group(
inside_res = aml_obj._read_group(
domain_base_w_start_end
+ [
("start_date", ">=", start_date),
("end_date", "<=", end_date),
],
["balance"],
[],
aggregates=["balance:sum"],
)
amount_inside = inside_res and inside_res[0]["balance"] or 0
amount_inside = inside_res and inside_res[0][0] or 0
amount += amount_inside * sign
# 3. Start/end dates, OVER interval
mlines = aml_obj.search(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
invisible="active"
/>
<div class="oe_title">
<label for="name" string="Subscription Name" class="oe_edit_only" />
Expand All @@ -31,7 +31,8 @@
<field name="partner_type" widget="radio" />
<field
name="partner_id"
attrs="{'invisible': [('partner_type', '!=', 'one')], 'required': [('partner_type', '=', 'one')]}"
invisible="partner_type != 'one'"
required="partner_type == 'one'"
/>
<field name="periodicity" />
<field name="start_date" />
Expand Down Expand Up @@ -63,7 +64,7 @@
<field name="partner_type" optional="show" />
<field
name="partner_id"
attrs="{'invisible': [('partner_type', '!=', 'one')]}"
invisible="partner_type != 'one'"
optional="show"
/>
<field name="periodicity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
<field name="inherit_id" ref="account_cutoff_base.account_cutoff_line_form" />
<field name="arch" type="xml">
<field name="parent_id" position="after">
<field
name="subscription_id"
attrs="{'invisible': [('subscription_id', '=', False)]}"
/>
<field name="subscription_id" invisible="not subscription_id" />
</field>
</field>
</record>
Expand Down

0 comments on commit 84ce2f4

Please sign in to comment.