pos_combo_tax/models/pos_order.py
2026-06-05 09:07:11 +07:00

46 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
from odoo import api, fields, models
from odoo.tools import float_is_zero
class PosOrder(models.Model):
_inherit = 'pos.order'
@api.model
def _get_invoice_lines_values(self, line_values, pos_line, move_type):
res = super()._get_invoice_lines_values(line_values, pos_line, move_type)
if pos_line.product_id.type == 'combo':
is_refund_order = bool(
pos_line.order_id.is_refund
or pos_line.order_id.amount_total < 0.0
)
qty_sign = -1 if (
(move_type == 'out_invoice' and is_refund_order)
or (move_type == 'out_refund' and not is_refund_order)
) else 1
res.update({
'display_type': False,
'product_id': line_values['product_id'].id,
'quantity': qty_sign * line_values['quantity'],
'discount': line_values['discount'],
'price_unit': line_values['price_unit'],
'name': line_values['name'],
'tax_ids': [(6, 0, line_values['tax_ids'].ids)],
'product_uom_id': line_values['uom_id'].id,
'extra_tax_data': self.env['account.tax']._export_base_line_extra_tax_data(line_values),
})
return res
class PosOrderLine(models.Model):
_inherit = 'pos.order.line'
@api.depends('price_subtotal', 'total_cost')
def _compute_margin(self):
super()._compute_margin()
for line in self:
if line.product_id.type == 'combo':
sign = -1 if line.order_id.is_refund else 1
line.margin = (line.price_subtotal * sign) - line.total_cost
line.margin_percent = not float_is_zero(line.price_subtotal, precision_rounding=line.currency_id.rounding) \
and line.margin / (line.price_subtotal * sign) \
or 0