Skip to content

Commit

Permalink
Merge PR #347 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by legalsylvain
  • Loading branch information
github-grap-bot committed Dec 19, 2023
2 parents 4191956 + d21d0f9 commit 173517c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
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()
if len(regex_result) == 1:
product_code = regex_result[0]
supplierinfos = supplierinfos.filtered(
lambda x: x.product_code == product_code
)
if len(supplierinfos) <= 1:
return supplierinfos

# 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

0 comments on commit 173517c

Please sign in to comment.