Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] grap_qweb_report : make xlsx purchase working if there are many supplierinfo for the same products #347

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions grap_qweb_report/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from . import purchase_order
from . import sale_order_line
from . import stock_picking
from . import product_product
33 changes: 33 additions & 0 deletions grap_qweb_report/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import re

from odoo import models


class ProductProduct(models.Model):
_inherit = "product.product"

def _get_supplierinfo_from_purchase_order_line(self, order_line):
self.ensure_one()
supplierinfos = order_line.product_id.seller_ids.filtered(
lambda x: x.name == order_line.order_id.partner_id
and (not x.product_id or x.product_id == order_line.product_id)
)
if len(supplierinfos) <= 1:
return supplierinfos
# Try to guess supplierinfo, from the code set in the order line name
regex_result = re.search(r"\[(\w+)\].*", order_line.name).groups()

Check warning on line 22 in grap_qweb_report/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

grap_qweb_report/models/product_product.py#L22

Added line #L22 was not covered by tests
if len(regex_result) == 1:
product_code = regex_result[0]

Check warning on line 24 in grap_qweb_report/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

grap_qweb_report/models/product_product.py#L24

Added line #L24 was not covered by tests
supplierinfos = supplierinfos.filtered(
lambda x: x.product_code == product_code
)
if len(supplierinfos) <= 1:
return supplierinfos

Check warning on line 29 in grap_qweb_report/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

grap_qweb_report/models/product_product.py#L29

Added line #L29 was not covered by tests

# The code has not been found or there is many supplierinfo with the same code
# Fallback and return the first supplierinfo
return supplierinfos.sorted(key=lambda x: x.min_qty)[0]
7 changes: 3 additions & 4 deletions grap_qweb_report/report/report_purchase_order_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ def generate_xlsx_report(self, workbook, data, orders):

def _get_columns_spec(self, order_lines):
supplierinfo_render = (
"order_line.product_id.seller_ids.filtered("
"lambda x: x.name == order_line.order_id.partner_id "
" and (not x.product_id or x.product_id == order_line.product_id))"
".sorted(key=lambda x: x.min_qty)"
"order_line.product_id"
"._get_supplierinfo_from_purchase_order_line(order_line)"
)

res = [
{
"name": "product_code",
Expand Down
Loading