Three related problems with Drop Shipping with Anglo Saxon Accounting.

One has been broken since #20080.

Another is caused by the same code.

The third - a fix from #12687 - is being bypassed by current code.



Impacted versions:

11.0, and 10.0 for at least some of this

Steps to reproduce:

Set up a product with
- real time valuation
- standard price
- Anglo Saxon accounting
- drop shipping turned on
- invoicing on delivered quantities

Create a product with a standard price of $40.

Current behavior:

_If I create a sales order and choose to ship from existing stock, then the invoice created after delivery is correct, and it has the correct Anglo Saxon account moves._

- Dr COGS $40
- Cr Output $40

If I create a sales order and choose to drop ship, I can then go to the RFQ, and change the RFQ price to $45, then receive the product, and generate the Vendor Bill.  Everything is correct at this point.  When I go back to the Sales Order and create and validate the invoice, it has the incorrect Anglo Saxon account moves:

- Dr Output $45
- Cr COGS $45

Expected behavior:

The accounting should be the same on the invoice.  The value is wrong, and the debits and credits are reversed.

Also, there should be an additional journal:

- Dr Output $40
- Cr Input $40

Th 3 problems are:

1. It is getting a -ve price unit from _compute_average_price because the stock move is not an outgoing move, but a supplier -> customer move!
2. It is getting the average price from those moves and using it, even if the product is using standard price.
3. The extra move that #12687 created is no longer being generated as the account moves are being bypassed entirely for dropshipping.  Somewhere in the process, we need to move the value from stock_input to stock_output.  This may be a v11 problem only.

Video/Screenshot link (optional):


from odoo import fields, models
class AccountInvoice(models.Model):
    _inherit = 'account.invoice'
    incoterms_id = fields.Many2one('stock.incoterms', string="Incoterms",
        help="Incoterms are series of sales terms. They are used to divide transaction costs and responsibilities between buyer and seller and reflect state-of-the-art transportation practices.",
        readonly=True, states={'draft': [('readonly', False)]})
class AccountInvoiceLine(models.Model):
    _inherit = "account.invoice.line"
    def _get_anglo_saxon_price_unit(self):
        price_unit = super(AccountInvoiceLine,self)._get_anglo_saxon_price_unit()
        
        
        if self.product_id.invoice_policy == "delivery":
            for s_line in self.sale_line_ids:
                
                qty_done = sum([x.uom_id._compute_quantity(x.quantity, x.product_id.uom_id) for x in s_line.invoice_lines if x.invoice_id.state in ('open', 'paid')])
                quantity = self.uom_id._compute_quantity(self.quantity, self.product_id.uom_id)
                
                moves = self.env['stock.move']
                moves |= s_line.move_ids
                moves.sorted(lambda x: x.date)
                
                
                
                average_price_unit = self._compute_average_price(qty_done, quantity, moves)
                price_unit = average_price_unit or price_unit
                price_unit = self.product_id.uom_id._compute_price(price_unit, self.uom_id)
        return price_unit
    def _compute_average_price(self, qty_done, quantity, moves):