This issue comes after I achieved this.
To sum it up, I created a new extra field for discount in Sale Order. It is calculated in subtotal. It is working as expected as the part of Sale Order.
After that, I confirmed it, sent products, and created invoice.
I found out that the subtotal in invoice created from that SO does not have the same value as in the SO because the subtotal in invoice does not calculate by including the extra discount.
I have looked into _create_invoices
method in Sale model but I have no clues where the subtotal calculation takes place.
My goal is to just make the invoice subtotal calculation get the same value as in the current SO subtotal. Of course, other calculated fields after subtotal as well such as Untaxed Amount, Taxes, and Total must match the SO too.
================
UPDATE
Okay now that I figured out which ones to use. I override only _get_price_total_and_subtotal_model
and _prepare_invoice_line
. This makes me able to send extra discount from sale to invoice. However, when I create invoice from sale, the unit price shown in invoice is reduced by the discount, but if I create invoice manually from invoice (I have extra discount field in invoice too) the unit price is not reduced by the extra discount, only the subtotal is discounted, which is the result I am looking for. The only issue is that why creating invoice from sale changes unit price?