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

[16.0][IMP] sale_order_invoicing_grouping_criteria: use odoo's grouping functions #1866

Draft
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Draft
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
40 changes: 9 additions & 31 deletions sale_order_invoicing_grouping_criteria/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,16 @@ def _get_grouping_partner(self):
If not set, use the partner_id.
:return: res.partner recordset
"""
self.ensure_one()
return self.partner_invoice_id or self.partner_id
res = self.env["res.partner"]
for sale in self:
res += sale.partner_invoice_id or sale.partner_id
return res

def _get_sale_invoicing_group_key(self):
"""Prepare extended grouping criteria for sales orders."""
self.ensure_one()
group_key = [
self.company_id.id,
self.partner_invoice_id.id,
self.currency_id.id,
]
partner = self._get_grouping_partner()
def _get_invoice_grouping_keys(self):
res = super()._get_invoice_grouping_keys()
partners = self._get_grouping_partner()
criteria = (
partner.sale_invoicing_grouping_criteria_id
partners.mapped("sale_invoicing_grouping_criteria_id")
or self.company_id.default_sale_invoicing_grouping_criteria_id
)
for field in criteria.field_ids.sudo():
group_key.append(self[field.name])
return tuple(group_key)

def _create_invoices(self, grouped=False, final=False, date=None):
"""Slice the batch according grouping criteria."""
order_groups = {}
for order in self:
group_key = order._get_sale_invoicing_group_key()
if group_key not in order_groups:
order_groups[group_key] = order
else:
order_groups[group_key] += order
moves = self.env["account.move"]
for group in order_groups.values():
moves += super(SaleOrder, group)._create_invoices(
grouped=grouped, final=final, date=date
)
return moves
return res + criteria.sudo().field_ids.mapped("name")
Loading