Skip to content

Commit

Permalink
Revert "[IMP] sale_order_invoicing_grouping_criteria: use odoo's grou…
Browse files Browse the repository at this point in the history
…ping functions"

This reverts commit 8a7666f.
  • Loading branch information
Tisho99 committed Dec 23, 2024
1 parent 8a7666f commit 79819a1
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions sale_order_invoicing_grouping_criteria/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,38 @@ def _get_grouping_partner(self):
If not set, use the partner_id.
:return: res.partner recordset
"""
res = self.env["res.partner"]
for sale in self:
res += sale.partner_invoice_id or sale.partner_id
return res
self.ensure_one()
return self.partner_invoice_id or self.partner_id

def _get_invoice_grouping_keys(self):
res = super()._get_invoice_grouping_keys()
partners = self._get_grouping_partner()
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()
criteria = (
partners.mapped("sale_invoicing_grouping_criteria_id")
partner.sale_invoicing_grouping_criteria_id
or self.company_id.default_sale_invoicing_grouping_criteria_id
)
return res + criteria.sudo().field_ids.mapped("name")
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

0 comments on commit 79819a1

Please sign in to comment.