Files
odoo_source/addons/mrp_account/models/account_move.py
T
Adrien WidartandFlorent de Labarre 707d6f9bf7 [FIX] {mrp_,}account,sale_{stock,mrp}: display lots in invoice
When invoicing a tracked product, the lots/SN delivered (or the related
quantities) are not always the correct ones displayed on the printed
invoice

To reproduce the issues:
1. In Settings, enable "Display Lots & Serial Numbers on Invoices"
2. Create a product P:
    - Storable
    - Tracked by lot
3. Update its quantity > 5 with lot L

Use case 01:

4. Create and confirm a SO with 5 x P
5. Process the delivery
6. Create an invoice
7. Edit the invoice line:
    - Quantity: 1
8. Post and print the invoice
Error: The quantity related to lot L is 5, it should be 1

Use case 02:

4. Edit P:
    - Invoicing Policy: Ordered quantities
5. Create and confirm a SO with 1 x P
6. Create and post the invoice
7. Process the delivery
8. Print the invoice
Error: There isn't any information about delivered lot L

Use case 03:

4. Create and confirm a SO with 3 x P
5. Deliver 1 x P (with backorder)
6. Invoice 1 x P + Post the invoice (-> INV01)
7. Deliver 2 x P
8. Reset, post INV01 again and print it
Error: The quantity related to L is 3, it should be 1. Moreover, if the
user then invoices the 2 others P, posts and prints this second invoice,
it won't contain any information about L

OPW-2730270
closes #81444

closes odoo/odoo#89088

X-original-commit: 3598c0c8cda813efa1aebc17f041e4c0a1a29f06
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Adrien Widart <awt@odoo.com>
Co-authored-by: Adrien Widart <awt@odoo.com>
Co-authored-by: Florent de Labarre <florent.mirieu@gmail.com>
2022-04-20 09:33:05 +02:00

29 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from collections import defaultdict
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
def _get_invoiced_qty_per_product(self):
# Replace the kit-type products with their components
qties = defaultdict(float)
res = super()._get_invoiced_qty_per_product()
invoiced_products = self.env['product.product'].concat(*res.keys())
bom_kits = self.env['mrp.bom']._bom_find(invoiced_products, company_id=self.company_id[:1].id, bom_type='phantom')
for product, qty in res.items():
bom_kit = bom_kits[product]
if bom_kit:
invoiced_qty = product.uom_id._compute_quantity(qty, bom_kit.product_uom_id, round=False)
factor = invoiced_qty / bom_kit.product_qty
dummy, bom_sub_lines = bom_kit.explode(product, factor)
for bom_line, bom_line_data in bom_sub_lines:
qties[bom_line.product_id] += bom_line.product_uom_id._compute_quantity(bom_line_data['qty'], bom_line.product_id.uom_id)
else:
qties[product] += qty
return qties