[FIX] stock_account: avoid reinvoice on cogs entry

Create a product category [FIFO] with:
- Costing Method: First In First Out (FIFO)
- Inventory Valuation: Automated
Create a product [PROD] having:
- Product category: [FIFO]
- Product Type: Storable Product
- Invoicing Policy: Delivered quantities
- Can be expensed: True
- Re-Invoice Expenses: At cost
Create a sales order with [PROD]
Confirm, Deliver
Open the created STJ journal entry:
- Reset to draft
- Add analytic account on a line
- Post again

To the sale order is added a reinvoice line with negative quantity.
This should not occur with cogs lines

opw-3199428

closes odoo/odoo#119048

X-original-commit: 347975d6d9b07db521e02ee12694aa834708abbe
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Grazioso Andrea (agr) <agr@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2023-04-19 21:58:45 +02:00
parent 8ec2e8cf80
commit c7c3f69453
2 changed files with 29 additions and 1 deletions
+1 -1
View File
@@ -113,7 +113,7 @@ class AccountMoveLine(models.Model):
def _sale_can_be_reinvoice(self):
self.ensure_one()
return self.display_type != 'cogs' and super(AccountMoveLine, self)._sale_can_be_reinvoice()
return self.move_type != 'entry' and self.display_type != 'cogs' and super(AccountMoveLine, self)._sale_can_be_reinvoice()
def _stock_account_get_anglo_saxon_price_unit(self):
self.ensure_one()
@@ -1686,3 +1686,31 @@ class TestAngloSaxonValuation(ValuationReconciliationTestCommon):
cogs_aml = amls.filtered(lambda aml: aml.account_id == self.company_data['default_account_expense'])
self.assertEqual(cogs_aml.debit, 10)
self.assertEqual(cogs_aml.credit, 0)
def test_fifo_edit_svl_without_reinvoice(self):
"""Edit SVL move line after delivering. Check no reinvoicing occurs."""
self.product.categ_id.property_cost_method = 'fifo'
self.product.invoice_policy = 'delivery'
self.product.standard_price = 10
self.product.expense_policy = 'cost'
self._fifo_in_one_eight_one_ten()
# Create and confirm a sale order for 2@12
sale_order = self._so_and_confirm_two_units()
self.assertEqual(len(sale_order.order_line), 1)
self.assertEqual(sale_order.order_line.product_uom_qty, 2.0)
# Deliver one.
sale_order.picking_ids.move_ids.quantity_done = 2
sale_order.picking_ids.button_validate()
svl_am = sale_order.order_line.move_ids.stock_valuation_layer_ids.account_move_id
svl_am.button_draft()
svl_line = svl_am.line_ids.filtered(lambda aml: aml.account_id == self.company_data['default_account_stock_out'])
svl_line.write({'analytic_distribution': {sale_order.analytic_account_id.id: 100}})
svl_am.action_post()
# Check no reinvoice line addded to the sale order
self.assertEqual(len(sale_order.order_line), 1)
self.assertEqual(sale_order.order_line.product_uom_qty, 2.0)