Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0] [FW] [IMP] fieldservice_sale: Only invoice invoiceable fsm order #1315

Open
wants to merge 7 commits into
base: 18.0
Choose a base branch
from
6 changes: 6 additions & 0 deletions .oca/oca-port/blacklist/fieldservice_account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pull_requests": {
"OCA/field-service#997": "dotfiles",
"OCA/field-service#999": "(auto) Nothing to port from PR #999"
}
}
6 changes: 6 additions & 0 deletions .oca/oca-port/blacklist/fieldservice_sale.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pull_requests": {
"OCA/field-service#931": "(auto) Nothing to port from PR #931",
"OCA/field-service#1122": "(auto) Nothing to port from PR #1122"
}
}
2 changes: 1 addition & 1 deletion fieldservice_account/models/fsm_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def _get_invoiceable_stage(self):
by other criteria
:return:
"""
return self.search(["is_invoiceable", "=", "True"])
return self.search([("is_invoiceable", "=", "True")])
25 changes: 24 additions & 1 deletion fieldservice_sale/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,31 @@
line.order_id._field_service_generation()
return lines

def _get_invoiceable_fsm_order_domain(self):
"""
Override this method to define more search criteria for invoiceable
fsm order
:return:
"""
invoiceable_stage_ids = self.env["fsm.stage"]._get_invoiceable_stage()
dom = [
"|",
("sale_line_id", "=", self.id),
("sale_id", "=", self.order_id.id),
("invoice_lines", "=", False),
]
if invoiceable_stage_ids:
dom.append(("stage_id", "in", invoiceable_stage_ids.ids))

Check warning on line 70 in fieldservice_sale/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

fieldservice_sale/models/sale_order_line.py#L70

Added line #L70 was not covered by tests
return dom

def _get_invoiceable_fsm_order(self):
dom = self._get_invoiceable_fsm_order_domain()
return self.env["fsm.order"].search(dom)

def _prepare_invoice_line(self, **optional_values):
res = super()._prepare_invoice_line(**optional_values)
if self.fsm_order_id:
res.update({"fsm_order_ids": [(4, self.fsm_order_id.id)]})
fsm_orders = self._get_invoiceable_fsm_order()
if fsm_orders:
res.update({"fsm_order_ids": [(6, 0, fsm_orders.ids)]})
return res