You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
822 B
26 lines
822 B
# -*- coding: utf-8 -*-
|
|
from openerp import models, fields, api
|
|
|
|
|
|
class ProductTemplate(models.Model):
|
|
_inherit = "product.template"
|
|
|
|
main_supplier_id = fields.Many2one(
|
|
'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):
|
|
# Calcule le vendeur associé qui a la date de début la plus récente
|
|
# et plus petite qu’aujourd’hui
|
|
for pt in self:
|
|
sellers_ids = pt._get_sorted_supplierinfo()
|
|
pt.main_supplier_id = sellers_ids and sellers_ids[0].name or False
|