mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP] agreement_rebate: Add active fields in settlements
TT34871
This commit is contained in:
@@ -32,6 +32,7 @@ class AgreementRebateSettlement(models.Model):
|
|||||||
amount_invoiced = fields.Float(string="Amount invoiced")
|
amount_invoiced = fields.Float(string="Amount invoiced")
|
||||||
amount_rebate = fields.Float(string="Amount rebate")
|
amount_rebate = fields.Float(string="Amount rebate")
|
||||||
invoice_id = fields.Many2one(comodel_name="account.move", string="Invoice")
|
invoice_id = fields.Many2one(comodel_name="account.move", string="Invoice")
|
||||||
|
active = fields.Boolean(default=True)
|
||||||
|
|
||||||
@api.model_create_multi
|
@api.model_create_multi
|
||||||
def create(self, vals_list):
|
def create(self, vals_list):
|
||||||
@@ -43,6 +44,17 @@ class AgreementRebateSettlement(models.Model):
|
|||||||
)
|
)
|
||||||
return super(AgreementRebateSettlement, self).create(vals_list)
|
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):
|
def _reverse_type_map(self, inv_type):
|
||||||
return {
|
return {
|
||||||
"out_invoice": "out_refund",
|
"out_invoice": "out_refund",
|
||||||
@@ -101,6 +113,13 @@ class AgreementRebateSettlement(models.Model):
|
|||||||
action["domain"] = [("id", "in", self.ids)]
|
action["domain"] = [("id", "in", self.ids)]
|
||||||
return action
|
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):
|
def action_show_agreement(self):
|
||||||
agreements = self.line_ids.mapped("agreement_id")
|
agreements = self.line_ids.mapped("agreement_id")
|
||||||
action = self.env.ref("agreement.agreement_action").read()[0]
|
action = self.env.ref("agreement.agreement_action").read()[0]
|
||||||
@@ -167,6 +186,7 @@ class AgreementRebateSettlementLine(models.Model):
|
|||||||
store=True,
|
store=True,
|
||||||
readonly=False,
|
readonly=False,
|
||||||
)
|
)
|
||||||
|
active = fields.Boolean(default=True)
|
||||||
|
|
||||||
@api.depends(
|
@api.depends(
|
||||||
"invoice_line_ids",
|
"invoice_line_ids",
|
||||||
@@ -188,6 +208,27 @@ class AgreementRebateSettlementLine(models.Model):
|
|||||||
else:
|
else:
|
||||||
line.invoice_status = "to_invoice"
|
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):
|
def _prepare_invoice(self):
|
||||||
"""
|
"""
|
||||||
Prepare the dict of values to create the new invoice for a sales order.
|
Prepare the dict of values to create the new invoice for a sales order.
|
||||||
|
|||||||
@@ -22,6 +22,14 @@
|
|||||||
string="Invoiced"
|
string="Invoiced"
|
||||||
domain="[('line_ids.invoice_status', '=', '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">
|
<group name="groupby">
|
||||||
<filter
|
<filter
|
||||||
name="partner_groupby"
|
name="partner_groupby"
|
||||||
@@ -29,6 +37,8 @@
|
|||||||
context="{'group_by': 'partner_id'}"
|
context="{'group_by': 'partner_id'}"
|
||||||
/>
|
/>
|
||||||
</group>
|
</group>
|
||||||
|
<separator />
|
||||||
|
<filter string="Date" name="date" context="{'group_by':'date'}" />
|
||||||
</search>
|
</search>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
@@ -62,15 +72,29 @@
|
|||||||
>
|
>
|
||||||
<span>Agreement</span>
|
<span>Agreement</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
name="action_show_settlement_lines"
|
||||||
|
type="object"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-list"
|
||||||
|
>
|
||||||
|
<span>Lines</span>
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
name="action_show_detail"
|
name="action_show_detail"
|
||||||
type="object"
|
type="object"
|
||||||
class="oe_stat_button"
|
class="oe_stat_button"
|
||||||
icon="fa-pencil-square-o"
|
icon="fa-table"
|
||||||
>
|
>
|
||||||
<span>Details</span>
|
<span>Details</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<widget
|
||||||
|
name="web_ribbon"
|
||||||
|
title="Archived"
|
||||||
|
bg_color="bg-danger"
|
||||||
|
attrs="{'invisible': [('active', '=', True)]}"
|
||||||
|
/>
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<group>
|
||||||
<field name="name" />
|
<field name="name" />
|
||||||
@@ -78,6 +102,7 @@
|
|||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="date" />
|
<field name="date" />
|
||||||
|
<field name="active" invisible="1" />
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
@@ -107,7 +132,7 @@
|
|||||||
<button
|
<button
|
||||||
name="action_show_detail"
|
name="action_show_detail"
|
||||||
type="object"
|
type="object"
|
||||||
icon="fa-pencil-square-o"
|
icon="fa-table"
|
||||||
string="Show details"
|
string="Show details"
|
||||||
attrs="{'invisible': [('rebate_type', '!=', 'line')]}"
|
attrs="{'invisible': [('rebate_type', '!=', 'line')]}"
|
||||||
/>
|
/>
|
||||||
@@ -140,7 +165,7 @@
|
|||||||
<button
|
<button
|
||||||
name="action_show_detail"
|
name="action_show_detail"
|
||||||
type="object"
|
type="object"
|
||||||
icon="fa-pencil-square-o"
|
icon="fa-table"
|
||||||
string="Show details"
|
string="Show details"
|
||||||
/>
|
/>
|
||||||
<field
|
<field
|
||||||
@@ -157,9 +182,8 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<search string="Search settlement lines">
|
<search string="Search settlement lines">
|
||||||
<field name="partner_id" operator="child_of" />
|
<field name="partner_id" operator="child_of" />
|
||||||
<separator />
|
|
||||||
<field name="agreement_id" string="Agreement" />
|
<field name="agreement_id" string="Agreement" />
|
||||||
<separator />
|
<field name="settlement_id" />
|
||||||
<filter
|
<filter
|
||||||
name="not_invoiced"
|
name="not_invoiced"
|
||||||
string="Not invoiced"
|
string="Not invoiced"
|
||||||
@@ -172,6 +196,12 @@
|
|||||||
/>
|
/>
|
||||||
<separator />
|
<separator />
|
||||||
<filter name="date" string="Period" date="date" />
|
<filter name="date" string="Period" date="date" />
|
||||||
|
<separator />
|
||||||
|
<filter
|
||||||
|
string="Archived"
|
||||||
|
name="inactive"
|
||||||
|
domain="[('active', '=', False)]"
|
||||||
|
/>
|
||||||
<group expand="0" string="Group By">
|
<group expand="0" string="Group By">
|
||||||
<filter
|
<filter
|
||||||
name="group_by_partner_id"
|
name="group_by_partner_id"
|
||||||
@@ -183,6 +213,11 @@
|
|||||||
string="Agreement"
|
string="Agreement"
|
||||||
context="{'group_by':'agreement_id'}"
|
context="{'group_by':'agreement_id'}"
|
||||||
/>
|
/>
|
||||||
|
<filter
|
||||||
|
name="group_by_settlement_id"
|
||||||
|
string="Settlement"
|
||||||
|
context="{'group_by':'settlement_id'}"
|
||||||
|
/>
|
||||||
<separator />
|
<separator />
|
||||||
<filter string="Date" name="date" context="{'group_by':'date'}" />
|
<filter string="Date" name="date" context="{'group_by':'date'}" />
|
||||||
</group>
|
</group>
|
||||||
|
|||||||
Reference in New Issue
Block a user