Browse Source

[FIX] strong typing required when comparing values in python3

pull/167/head
robin.keunen 4 years ago
parent
commit
1756698cde
  1. 13
      beesdoo_product/models/beesdoo_product.py
  2. 17
      purchase_order_generator/models/product_template.py

13
beesdoo_product/models/beesdoo_product.py

@ -3,6 +3,7 @@
import logging
import uuid
from datetime import date
from odoo import api, fields, models
from odoo.exceptions import UserError, ValidationError
@ -95,9 +96,15 @@ class BeesdooProduct(models.Model):
product.scale_sale_unit = "P"
def _get_main_supplier_info(self):
suppliers = self.seller_ids.sorted(
key=lambda seller: seller.date_start, reverse=True
)
far_future = date(3000, 1, 1)
def sort_date_first(seller):
if seller.date_start:
return seller.date_start
else:
return far_future
suppliers = self.seller_ids.sorted(key=sort_date_first, reverse=True)
if suppliers:
return suppliers[0]
else:

17
purchase_order_generator/models/product_template.py

@ -3,6 +3,8 @@
# Vincent Van Rossem <vincent@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from datetime import date
from odoo import api, fields, models
@ -13,17 +15,20 @@ class ProductTemplate(models.Model):
"res.partner", compute="_compute_main_supplier_id", store=True
)
def _get_sorted_supplierinfo(self):
return self.seller_ids.sorted(
key=lambda seller: seller.date_start, reverse=True
)
@api.multi
@api.depends("seller_ids", "seller_ids.date_start")
def _compute_main_supplier_id(self):
far_future = date(3000, 1, 1)
def sort_date_first(seller):
if seller.date_start:
return seller.date_start
else:
return far_future
for pt in self:
sellers_ids = pt.seller_ids.sorted(
key=lambda seller: seller.date_start, reverse=True
key=sort_date_first, reverse=True
)
if sellers_ids:
pt.main_supplier_id = sellers_ids[0].name

Loading…
Cancel
Save