Browse Source
Merge pull request #167 from beescoop/12.0-fix-main_supplier_id
[FIX] strong typing required when comparing values in python3
pull/168/head
Houssine BAKKALI
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
21 additions and
9 deletions
-
beesdoo_product/models/beesdoo_product.py
-
purchase_order_generator/models/product_template.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: |
|
|
|
|
|
@ -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 |
|
|
|