Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions recurring_contract/models/recurring_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,34 @@ def create(self, vals_list):
vals["reference"] = self.env["ir.sequence"].next_by_code(
"recurring.contract.ref"
)
if not vals.get("group_id") and vals.get("partner_id"):
vals["group_id"] = self._default_group(vals["partner_id"]).id
res = super().create(vals_list)
return res

def _default_group(self, partner_id):
"""Billing group to use when none was picked on the contract (T3411).

Restricted to groups without a payment mode: no collection method was
chosen here, so we must not attach the contract to an existing
arrangement (LSV, Permanent Order, ...) the sponsor never agreed to.
The mode is set later, once it is.
"""
group_model = self.env["recurring.contract.group"]
company = self.env.company
group = group_model.search(
[
("partner_id", "=", partner_id),
("company_id", "=", company.id),
("payment_mode_id", "=", False),
],
order="id desc",
limit=1,
)
Comment thread
greptile-apps[bot] marked this conversation as resolved.
return group or group_model.create(
{"partner_id": partner_id, "company_id": company.id}
Comment thread
Danielgergely marked this conversation as resolved.
)

def write(self, vals):
"""Perform various checks when a contract is modified."""
res = super().write(vals)
Expand Down
2 changes: 2 additions & 0 deletions recurring_contract/views/recurring_contract_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
domain="[('partner_id', '=', partner_id)]"
context="{'default_partner_id': partner_id, 'contract_id': id,}"
options="{'no_quick_create': True}"
required="0"
placeholder="Created automatically if left empty"
/>
<field
name="company_id"
Expand Down
Loading