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):


addons/stock_account/models/stock.py
if not price_diff_account:
                raise UserError(_('Configuration error. Please configure the price difference account on the product or its category to process this operation.'))
            price_diff_line = {
                'name': self.name,
                'product_id': self.product_id.id,
                'quantity': qty,
                'product_uom_id': self.product_id.uom_id.id,
                'ref': self.picking_id.name,
                'partner_id': partner_id,
                'credit': diff_amount > 0 and diff_amount or 0,
                'debit': diff_amount < 0 and -diff_amount or 0,
                'account_id': price_diff_account.id,
            }
            res.append((0, 0, price_diff_line))
        return res
    def _create_account_move_line(self, credit_account_id, debit_account_id, journal_id):
        self.ensure_one()
        AccountMove = self.env['account.move']
        move_lines = self._prepare_account_move_line(self.product_qty, abs(self.value), credit_account_id, debit_account_id)
        if move_lines:
            date = self._context.get('force_period_date', fields.Date.context_today(self))
            new_account_move = AccountMove.create({
                'journal_id': journal_id,
                'line_ids': move_lines,
                'date': date,
                'ref': self.picking_id.name,
                'stock_move_id': self.id,
            })
            new_account_move.post()
    def _account_entry_move(self):