[FIX] point_of_sale: use correct account in ship later pickings

Commit 1e82e27 makes ship later option create additionnal account
move line for Cogs at delivery validation. The issue is the accounts was
not correct. The desire result should be the following for a product of
cost 10, sale price 11 and 15% taxes.

 At PoS Closing                             | Debit | Credit
-------------------------------------------------------------
215000 Taxes 15%                            |  0.00 |   1.50
200000 Pos account                          |  0.00 |  11.00
600000 Expenses                             |  0.00 |   0.00
101200 Account Receivable                   | 11.50 |   0.00
110300 Stock interim (delivered)            |  0.00 |   0.00
-------------------------------------------------------------
                                            |       |
 At delivery validation (manually created)  |       |
-------------------------------------------------------------
110300 Stock interim (delivered)            |  0.00 |  10.00
600000 Expenses                             | 10.00 |   0.00
-------------------------------------------------------------
                                            |       |
 At delivery validation (from stock layers) |       |
-------------------------------------------------------------
110100 Stock valuation                      |  0.00 |  10.00
110300 Stock interim (delivered)            | 10.00 |   0.00

Opw: 3324972
X-original-commit: 471e4c6e9c9aa396060a29725aca88360e781960
Part-of: odoo/odoo#125850
This commit is contained in:
William Henrotin
2023-06-21 11:50:19 +02:00
parent da6fcc9ae6
commit 7df2c48d5d
2 changed files with 45 additions and 29 deletions
+32 -23
View File
@@ -120,30 +120,39 @@ class StockPicking(models.Model):
def _action_done(self):
res = super()._action_done()
if self.pos_order_id.shipping_date and not self.pos_order_id.to_invoice:
order_cost = sum(line.total_cost for line in self.pos_order_id.lines)
move_vals = {
'journal_id': self.pos_order_id.sale_journal.id,
'date': self.pos_order_id.date_order,
'ref': self.pos_order_id.name,
'line_ids': [
(0, 0, {
'name': self.pos_order_id.name,
'account_id': self.product_id.categ_id.property_account_income_categ_id.id,
'debit': order_cost,
'credit': 0.0,
}),
(0, 0, {
'name': self.pos_order_id.name,
'account_id': self.product_id.categ_id.property_account_expense_categ_id.id,
'debit': 0.0,
'credit': order_cost,
for rec in self:
if rec.pos_order_id.shipping_date and not rec.pos_order_id.to_invoice:
cost_per_account = defaultdict(lambda: 0.0)
for line in rec.pos_order_id.lines:
if line.product_id.type != 'product':
continue
out = line.product_id.categ_id.property_stock_account_output_categ_id
exp = line.product_id._get_product_accounts()['expense']
cost_per_account[(out, exp)] += line.total_cost
move_vals = []
for (out_acc, exp_acc), cost in cost_per_account.items():
move_vals.append({
'journal_id': rec.pos_order_id.sale_journal.id,
'date': rec.pos_order_id.date_order,
'ref': rec.pos_order_id.name,
'line_ids': [
(0, 0, {
'name': rec.pos_order_id.name,
'account_id': exp_acc.id,
'debit': cost,
'credit': 0.0,
}),
(0, 0, {
'name': rec.pos_order_id.name,
'account_id': out_acc.id,
'debit': 0.0,
'credit': cost,
}),
],
})
]
}
move = self.env['account.move'].create(move_vals)
self.pos_order_id.write({'account_move': move.id})
move.action_post()
move = self.env['account.move'].create(move_vals)
rec.pos_order_id.write({'account_move': move.id})
move.action_post()
return res
class StockPickingType(models.Model):
+13 -6
View File
@@ -283,13 +283,20 @@ class TestAngloSaxonFlow(TestAngloSaxonCommon):
aml_output = aml.filtered(lambda l: l.account_id.id == account_output.id)
aml_expense = aml.filtered(lambda l: l.account_id.id == expense_account.id)
self.assertEqual(len(aml_output), 3, "There should be 3 output account move lines")
# 2 moves in POS journal (Pos order + manual entry at delivery)
self.assertEqual(aml_output[:2].move_id.journal_id, self.pos_config.journal_id)
# 1 move in stock journal (delivery from stock layers)
self.assertEqual(aml_output[2].move_id.journal_id, self.category.property_stock_journal)
#Check the lines created after the picking validation
self.assertEqual(aml_output[1].debit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_output[1].credit, 0.0, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_expense[0].credit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_expense[0].debit, 0.0, "Cost of Good Sold entry missing or mismatching")
#Check the lines created by the PoS session
self.assertEqual(aml_output[0].credit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_output[0].debit, 0.0, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_output[0].credit, 0.0, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_output[2].debit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_output[2].credit, 0.0, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_expense[0].debit, self.product.standard_price, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_expense[0].credit, 0.0, "Cost of Good Sold entry missing or mismatching")
#Check the lines created by the PoS session
self.assertEqual(aml_output[1].debit, 0.0, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_output[1].credit, 0.0, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_expense[1].credit, 0.0, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_expense[1].debit, 0.0, "Cost of Good Sold entry missing or mismatching")