feat: Add handling for POS orders without payment records by routing amounts to split sales via a fallback cash payment method.
This commit is contained in:
parent
eace0d7625
commit
e96bceedf6
@ -154,6 +154,55 @@ class PosSession(models.Model):
|
|||||||
if float_is_zero(order_amount, precision_rounding=self.currency_id.rounding):
|
if float_is_zero(order_amount, precision_rounding=self.currency_id.rounding):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if not order.payment_ids:
|
||||||
|
# Assume cash payment method for 0-total orders to ensure proper routing and naming
|
||||||
|
cash_pm = self.payment_method_ids.filtered(lambda pm: pm.type == 'cash')[:1]
|
||||||
|
fallback_pm_id = cash_pm.id if cash_pm else False
|
||||||
|
|
||||||
|
regular_part_amount = order_sale_amounts['regular_amount']
|
||||||
|
discount_part_amount = order_sale_amounts['discount_amount']
|
||||||
|
regular_part_amount_converted = order_sale_amounts['regular_amount_converted']
|
||||||
|
discount_part_amount_converted = order_sale_amounts['discount_amount_converted']
|
||||||
|
regular_part_tax = order_sale_amounts['regular_tax_amount']
|
||||||
|
discount_part_tax = order_sale_amounts['discount_tax_amount']
|
||||||
|
|
||||||
|
def add_unsplit_entry(part_amount, part_amount_converted, part_tax_amount, is_discount_part):
|
||||||
|
if float_is_zero(part_amount, precision_rounding=self.currency_id.rounding):
|
||||||
|
return
|
||||||
|
|
||||||
|
target_account_id = sale_key[0]
|
||||||
|
if fallback_pm_id and cash_pm:
|
||||||
|
original_account = self.env['account.account'].browse(target_account_id)
|
||||||
|
is_income_account = original_account.account_type in ('income', 'income_other')
|
||||||
|
if is_income_account:
|
||||||
|
if is_discount_part:
|
||||||
|
if cash_pm.discount_account_id:
|
||||||
|
target_account_id = cash_pm.discount_account_id.id
|
||||||
|
elif cash_pm.income_account_id:
|
||||||
|
target_account_id = cash_pm.income_account_id.id
|
||||||
|
else:
|
||||||
|
if cash_pm.income_account_id:
|
||||||
|
target_account_id = cash_pm.income_account_id.id
|
||||||
|
|
||||||
|
if fallback_pm_id:
|
||||||
|
new_sale_key = (
|
||||||
|
target_account_id,
|
||||||
|
sale_key[1],
|
||||||
|
fallback_pm_id,
|
||||||
|
sale_key[2],
|
||||||
|
sale_key[3],
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
new_sale_key = sale_key
|
||||||
|
|
||||||
|
split_sales[new_sale_key]['amount'] += part_amount
|
||||||
|
split_sales[new_sale_key]['amount_converted'] += part_amount_converted
|
||||||
|
split_sales[new_sale_key]['tax_amount'] += part_tax_amount
|
||||||
|
|
||||||
|
add_unsplit_entry(regular_part_amount, regular_part_amount_converted, regular_part_tax, False)
|
||||||
|
add_unsplit_entry(discount_part_amount, discount_part_amount_converted, discount_part_tax, True)
|
||||||
|
continue
|
||||||
|
|
||||||
for payment in order.payment_ids:
|
for payment in order.payment_ids:
|
||||||
#if float_is_zero(payment.amount, precision_rounding=order.currency_id.rounding):
|
#if float_is_zero(payment.amount, precision_rounding=order.currency_id.rounding):
|
||||||
# continue
|
# continue
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user