[FIX] contract: remove groupby if it is in context + consistency between contract count and contract action

On the commercial entity, the count shows all contracts of child partners.
However clicking on the action might show no contract, as the action only
restricted the domain to the partner itself.
We extract the domain into a function to share it in both cases.

Co-authored by @Lopsanz
This commit is contained in:
nans
2021-02-15 10:27:45 +01:00
committed by Christopher Rogos
parent 7cf5d4547c
commit de55a7fb08
2 changed files with 11 additions and 10 deletions

View File

@@ -11,7 +11,7 @@
{ {
"name": "Recurring - Contracts Management", "name": "Recurring - Contracts Management",
"version": "13.0.2.3.3", "version": "13.0.2.3.5",
"category": "Contract Management", "category": "Contract Management",
"license": "AGPL-3", "license": "AGPL-3",
"author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)", "author": "Tecnativa, ACSONE SA/NV, Odoo Community Association (OCA)",

View File

@@ -17,10 +17,14 @@ class ResPartner(models.Model):
comodel_name="contract.contract", inverse_name="partner_id", string="Contracts", comodel_name="contract.contract", inverse_name="partner_id", string="Contracts",
) )
def _get_partner_contract_domain(self):
self.ensure_one()
return [("partner_id", "child_of", self.ids)]
def _compute_contract_count(self): def _compute_contract_count(self):
contract_model = self.env["contract.contract"] contract_model = self.env["contract.contract"]
fetch_data = contract_model.read_group( fetch_data = contract_model.read_group(
[("partner_id", "child_of", self.ids)], self._get_partner_contract_domain(),
["partner_id", "contract_type"], ["partner_id", "contract_type"],
["partner_id", "contract_type"], ["partner_id", "contract_type"],
lazy=False, lazy=False,
@@ -50,14 +54,11 @@ class ResPartner(models.Model):
contract_type = self._context.get("contract_type") contract_type = self._context.get("contract_type")
res = self._get_act_window_contract_xml(contract_type) res = self._get_act_window_contract_xml(contract_type)
res.update( action_context = {k: v for k, v in self.env.context.items() if k != "group_by"}
context=dict( action_context["domain"] = self._get_partner_contract_domain()
self.env.context, action_context["default_partner_id"] = self.id
search_default_partner_id=self.id, action_context["default_pricelist_id"] = self.property_product_pricelist.id
default_partner_id=self.id, res["context"] = action_context
default_pricelist_id=self.property_product_pricelist.id,
),
)
return res return res
def _get_act_window_contract_xml(self, contract_type): def _get_act_window_contract_xml(self, contract_type):