[IMP] agreement_rebate: Add active fields in settlements

TT34871
This commit is contained in:
Carlos Dauden
2022-03-07 18:48:18 +01:00
parent a8cc93ad16
commit da8bb79f58
2 changed files with 81 additions and 5 deletions

View File

@@ -32,6 +32,7 @@ class AgreementRebateSettlement(models.Model):
amount_invoiced = fields.Float(string="Amount invoiced")
amount_rebate = fields.Float(string="Amount rebate")
invoice_id = fields.Many2one(comodel_name="account.move", string="Invoice")
active = fields.Boolean(default=True)
@api.model_create_multi
def create(self, vals_list):
@@ -43,6 +44,17 @@ class AgreementRebateSettlement(models.Model):
)
return super(AgreementRebateSettlement, self).create(vals_list)
def write(self, vals):
res = super().write(vals)
if "active" in vals and not self.env.context.get(
"skip_active_field_update", False
):
lines = self.with_context(active_test=False).line_ids.filtered(
lambda ln: ln.active != vals["active"]
)
lines.with_context(skip_active_field_update=True).active = vals["active"]
return res
def _reverse_type_map(self, inv_type):
return {
"out_invoice": "out_refund",
@@ -101,6 +113,13 @@ class AgreementRebateSettlement(models.Model):
action["domain"] = [("id", "in", self.ids)]
return action
def action_show_settlement_lines(self):
action = self.env.ref(
"agreement_rebate.agreement_rebate_settlement_line_action"
).read()[0]
action["domain"] = [("settlement_id", "in", self.ids)]
return action
def action_show_agreement(self):
agreements = self.line_ids.mapped("agreement_id")
action = self.env.ref("agreement.agreement_action").read()[0]
@@ -167,6 +186,7 @@ class AgreementRebateSettlementLine(models.Model):
store=True,
readonly=False,
)
active = fields.Boolean(default=True)
@api.depends(
"invoice_line_ids",
@@ -188,6 +208,27 @@ class AgreementRebateSettlementLine(models.Model):
else:
line.invoice_status = "to_invoice"
def write(self, vals):
res = super().write(vals)
if "active" in vals and not self.env.context.get(
"skip_active_field_update", False
):
if vals["active"]:
# If one line is active settlement must be active
settlements = self.mapped("settlement_id").filtered(
lambda s: not s.active
)
else:
# If lines are archived and the settlement has not active lines, the
# settlement must be archived
settlements = self.mapped("settlement_id").filtered(
lambda s: s.active and not s.line_ids
)
settlements.with_context(skip_active_field_update=True).active = vals[
"active"
]
return res
def _prepare_invoice(self):
"""
Prepare the dict of values to create the new invoice for a sales order.

View File

@@ -22,6 +22,14 @@
string="Invoiced"
domain="[('line_ids.invoice_status', '=', 'invoiced')]"
/>
<separator />
<filter name="date" string="Period" date="date" />
<separator />
<filter
string="Archived"
name="inactive"
domain="[('active', '=', False)]"
/>
<group name="groupby">
<filter
name="partner_groupby"
@@ -29,6 +37,8 @@
context="{'group_by': 'partner_id'}"
/>
</group>
<separator />
<filter string="Date" name="date" context="{'group_by':'date'}" />
</search>
</field>
</record>
@@ -62,15 +72,29 @@
>
<span>Agreement</span>
</button>
<button
name="action_show_settlement_lines"
type="object"
class="oe_stat_button"
icon="fa-list"
>
<span>Lines</span>
</button>
<button
name="action_show_detail"
type="object"
class="oe_stat_button"
icon="fa-pencil-square-o"
icon="fa-table"
>
<span>Details</span>
</button>
</div>
<widget
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
/>
<group>
<group>
<field name="name" />
@@ -78,6 +102,7 @@
</group>
<group>
<field name="date" />
<field name="active" invisible="1" />
</group>
</group>
<group>
@@ -107,7 +132,7 @@
<button
name="action_show_detail"
type="object"
icon="fa-pencil-square-o"
icon="fa-table"
string="Show details"
attrs="{'invisible': [('rebate_type', '!=', 'line')]}"
/>
@@ -140,7 +165,7 @@
<button
name="action_show_detail"
type="object"
icon="fa-pencil-square-o"
icon="fa-table"
string="Show details"
/>
<field
@@ -157,9 +182,8 @@
<field name="arch" type="xml">
<search string="Search settlement lines">
<field name="partner_id" operator="child_of" />
<separator />
<field name="agreement_id" string="Agreement" />
<separator />
<field name="settlement_id" />
<filter
name="not_invoiced"
string="Not invoiced"
@@ -172,6 +196,12 @@
/>
<separator />
<filter name="date" string="Period" date="date" />
<separator />
<filter
string="Archived"
name="inactive"
domain="[('active', '=', False)]"
/>
<group expand="0" string="Group By">
<filter
name="group_by_partner_id"
@@ -183,6 +213,11 @@
string="Agreement"
context="{'group_by':'agreement_id'}"
/>
<filter
name="group_by_settlement_id"
string="Settlement"
context="{'group_by':'settlement_id'}"
/>
<separator />
<filter string="Date" name="date" context="{'group_by':'date'}" />
</group>