[FIX] anglo_saxon_dropshipping: fix accounting entries creating on anglo_saxon + real_time + dropship.
This revert the fix made on 7bdd4de
and replace it with a proper one that do create an account entry from stock_input to stock_output on a dropship move. That way, we avoid the manual change of account on supplier invoice. See the whole discussion on odoo#12687
This commit is contained in:
parent
d1c81f136c
commit
001610ece9
|
@ -2,14 +2,32 @@
|
|||
|
||||
from openerp.osv import osv
|
||||
|
||||
class account_invoice_line(osv.osv):
|
||||
_inherit = 'account.invoice.line'
|
||||
|
||||
def _anglo_saxon_sale_move_lines(self, cr, uid, i_line, res, context=None):
|
||||
salelines = self.pool.get('sale.order.line').search(cr, uid, [('invoice_lines', 'in', [i_line.id])])
|
||||
for sale_line in self.pool.get('sale.order.line').browse(cr, uid, salelines, context=context):
|
||||
for proc in sale_line.procurement_ids:
|
||||
if proc.purchase_line_id:
|
||||
#if the invoice line is related to sale order lines having one of its procurement_ids with a purchase_line_id set, it means that it is a confirmed dropship and in that case we mustn't create the cost of sale line (because the product won't enter the stock)
|
||||
return []
|
||||
return super(account_invoice_line, self)._anglo_saxon_sale_move_lines(cr, uid, i_line, res, context=context)
|
||||
class stock_quant(osv.osv):
|
||||
_inherit = "stock.quant"
|
||||
|
||||
def _account_entry_move(self, cr, uid, quants, move, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
#checks to see if we need to create accounting entries
|
||||
if move.product_id.valuation != 'real_time':
|
||||
return super(stock_quant, self)._account_entry_move(cr, uid, quants, move, context=context)
|
||||
for q in quants:
|
||||
if q.owner_id:
|
||||
#if the quant isn't owned by the company, we don't make any valuation entry
|
||||
return super(stock_quant, self)._account_entry_move(cr, uid, quants, move, context=context)
|
||||
if q.qty <= 0:
|
||||
#we don't make any stock valuation for negative quants because the valuation is already made for the counterpart.
|
||||
#At that time the valuation will be made at the product cost price and afterward there will be new accounting entries
|
||||
#to make the adjustments when we know the real cost price.
|
||||
return super(stock_quant, self)._account_entry_move(cr, uid, quants, move, context=context)
|
||||
|
||||
if move.location_id.usage == 'supplier' and move.location_dest_id.usage == 'customer':
|
||||
#Creates an account entry from stock_input to stock_output on a dropship move. https://github.com/odoo/odoo/issues/12687
|
||||
ctx = context.copy()
|
||||
ctx['force_company'] = move.company_id.id
|
||||
journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation(cr, uid, move, context=ctx)
|
||||
return self._create_account_move_line(cr, uid, quants, move, acc_src, acc_dest, journal_id, context=ctx)
|
||||
|
||||
return super(stock_quant, self)._account_entry_move(cr, uid, quants, move, context=context)
|
||||
|
|
Loading…
Reference in New Issue