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
journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation()
            if location_to and location_to.usage == 'supplier':  
                self.with_context(force_company=company_from.id)._create_account_move_line(acc_valuation, acc_src, journal_id)
            else:
                self.with_context(force_company=company_from.id)._create_account_move_line(acc_valuation, acc_dest, journal_id)
        if self.company_id.anglo_saxon_accounting and self.location_id.usage == 'supplier' and self.location_dest_id.usage == 'customer':
            
            journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation()
            self.with_context(force_company=self.company_id.id)._create_account_move_line(acc_src, acc_dest, journal_id)
class StockReturnPicking(models.TransientModel):
    _inherit = "stock.return.picking"
    @api.multi
    def _create_returns(self):
        new_picking_id, pick_type_id = super(StockReturnPicking, self)._create_returns()
        new_picking = self.env['stock.picking'].browse([new_picking_id])
        for move in new_picking.move_lines:
            return_picking_line = self.product_return_moves.filtered(lambda r: r.move_id == move.origin_returned_move_id)
            if return_picking_line and return_picking_line.to_refund:
                move.to_refund = True
        return new_picking_id, pick_type_id
class StockReturnPickingLine(models.TransientModel):
    _inherit = "stock.return.picking.line"
    to_refund = fields.Boolean(string="To Refund (update SO/PO)", help='Trigger a decrease of the delivered/received quantity in the associated Sale Order/Purchase Order')
class ProcurementGroup(models.Model):
    _inherit = 'procurement.group'
    @api.model
    def _run_scheduler_tasks(self, use_new_cursor=False, company_id=False):
        super(ProcurementGroup, self)._run_scheduler_tasks(use_new_cursor=use_new_cursor, company_id=company_id)
        self.env['stock.move']._run_fifo_vacuum()