Skip to content

Commit

Permalink
[IMP] stock_account: add hook on anglosaxon dropshipping entries
Browse files Browse the repository at this point in the history
The goal is to modify the acconuts that take please in those entries.
A typical example is a company that wants to recognize cost of goods
sold for the input and output at the same time, instead of waiting
for the customer invoice.

closes #160295

X-original-commit: 4de2520
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
  • Loading branch information
AaronHForgeFlow authored and Whenrow committed Apr 11, 2024
1 parent 32d9df4 commit e5c3ba5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions addons/stock_account/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,23 +595,30 @@ def _account_entry_move(self, qty, description, svl_id, cost):

if self.company_id.anglo_saxon_accounting:
# Creates an account entry from stock_input to stock_output on a dropship move. https://github.com/odoo/odoo/issues/12687
if self._is_dropshipped():
if cost > 0:
am_vals.append(self.with_company(self.company_id)._prepare_account_move_vals(acc_src, acc_valuation, journal_id, qty, description, svl_id, cost))
else:
cost = -1 * cost
am_vals.append(self.with_company(self.company_id)._prepare_account_move_vals(acc_valuation, acc_dest, journal_id, qty, description, svl_id, cost))
elif self._is_dropshipped_returned():
if cost > 0 and self.location_dest_id._should_be_valued():
am_vals.append(self.with_company(self.company_id).with_context(is_returned=True)._prepare_account_move_vals(acc_valuation, acc_src, journal_id, qty, description, svl_id, cost))
elif cost > 0:
am_vals.append(self.with_company(self.company_id).with_context(is_returned=True)._prepare_account_move_vals(acc_dest, acc_valuation, journal_id, qty, description, svl_id, cost))
else:
cost = -1 * cost
am_vals.append(self.with_company(self.company_id).with_context(is_returned=True)._prepare_account_move_vals(acc_valuation, acc_src, journal_id, qty, description, svl_id, cost))
anglosaxon_am_vals = self._prepare_anglosaxon_account_move_vals(acc_src, acc_dest, acc_valuation, journal_id, qty, description, svl_id, cost)
if anglosaxon_am_vals:
am_vals.append(anglosaxon_am_vals)

return am_vals

def _prepare_anglosaxon_account_move_vals(self, acc_src, acc_dest, acc_valuation, journal_id, qty, description, svl_id, cost):
anglosaxon_am_vals = {}
if self._is_dropshipped():
if cost > 0:
anglosaxon_am_vals = self.with_company(self.company_id)._prepare_account_move_vals(acc_src, acc_valuation, journal_id, qty, description, svl_id, cost)
else:
cost = -1 * cost
anglosaxon_am_vals = self.with_company(self.company_id)._prepare_account_move_vals(acc_valuation, acc_dest, journal_id, qty, description, svl_id, cost)
elif self._is_dropshipped_returned():
if cost > 0 and self.location_dest_id._should_be_valued():
anglosaxon_am_vals = self.with_company(self.company_id).with_context(is_returned=True)._prepare_account_move_vals(acc_valuation, acc_src, journal_id, qty, description, svl_id, cost)
elif cost > 0:
anglosaxon_am_vals = self.with_company(self.company_id).with_context(is_returned=True)._prepare_account_move_vals(acc_dest, acc_valuation, journal_id, qty, description, svl_id, cost)
else:
cost = -1 * cost
anglosaxon_am_vals = self.with_company(self.company_id).with_context(is_returned=True)._prepare_account_move_vals(acc_valuation, acc_src, journal_id, qty, description, svl_id, cost)
return anglosaxon_am_vals

def _get_analytic_account(self):
return False

Expand Down

0 comments on commit e5c3ba5

Please sign in to comment.