|
@ -1,4 +1,3 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
|
import logging |
|
|
import logging |
|
|
|
|
|
|
|
|
from odoo import models, fields, api |
|
|
from odoo import models, fields, api |
|
@ -151,13 +150,13 @@ class ComputedPurchaseOrderLine(models.Model): |
|
|
|
|
|
|
|
|
if len(si) == 0: |
|
|
if len(si) == 0: |
|
|
raise ValidationError( |
|
|
raise ValidationError( |
|
|
u'No supplier information set for {name}' |
|
|
|
|
|
|
|
|
'No supplier information set for {name}' |
|
|
.format(name=cpol.product_template_id.name)) |
|
|
.format(name=cpol.product_template_id.name)) |
|
|
elif len(si) == 1: |
|
|
elif len(si) == 1: |
|
|
cpol.supplierinfo_id = si |
|
|
cpol.supplierinfo_id = si |
|
|
else: |
|
|
else: |
|
|
_logger.warning( |
|
|
_logger.warning( |
|
|
u'product {name} has several suppliers, chose last' |
|
|
|
|
|
|
|
|
'product {name} has several suppliers, chose last' |
|
|
.format(name=cpol.product_template_id.name) |
|
|
.format(name=cpol.product_template_id.name) |
|
|
) |
|
|
) |
|
|
si = si.sorted(key=lambda r: r.create_date, reverse=True) |
|
|
si = si.sorted(key=lambda r: r.create_date, reverse=True) |
|
@ -167,10 +166,10 @@ class ComputedPurchaseOrderLine(models.Model): |
|
|
def _check_minimum_purchase_quantity(self): |
|
|
def _check_minimum_purchase_quantity(self): |
|
|
for cpol in self: |
|
|
for cpol in self: |
|
|
if cpol.purchase_quantity < 0: |
|
|
if cpol.purchase_quantity < 0: |
|
|
raise ValidationError(u'Purchase quantity for {product_name} must be greater than 0' # noqa |
|
|
|
|
|
|
|
|
raise ValidationError('Purchase quantity for {product_name} must be greater than 0' # noqa |
|
|
.format(product_name=cpol.product_template_id.name)) |
|
|
.format(product_name=cpol.product_template_id.name)) |
|
|
elif 0 < cpol.purchase_quantity < cpol.minimum_purchase_qty: |
|
|
elif 0 < cpol.purchase_quantity < cpol.minimum_purchase_qty: |
|
|
raise ValidationError(u'Purchase quantity for {product_name} must be greater than {min_qty}' # noqa |
|
|
|
|
|
|
|
|
raise ValidationError('Purchase quantity for {product_name} must be greater than {min_qty}' # noqa |
|
|
.format(product_name=cpol.product_template_id.name, |
|
|
.format(product_name=cpol.product_template_id.name, |
|
|
min_qty=cpol.minimum_purchase_qty)) |
|
|
min_qty=cpol.minimum_purchase_qty)) |
|
|
|
|
|
|
|
@ -191,6 +190,6 @@ class ComputedPurchaseOrderLine(models.Model): |
|
|
return products[0] |
|
|
return products[0] |
|
|
else: |
|
|
else: |
|
|
raise ValidationError( |
|
|
raise ValidationError( |
|
|
u'%s:%s template has no variant set' |
|
|
|
|
|
|
|
|
'%s:%s template has no variant set' |
|
|
% (self.product_template_id.id, self.product_template_id.name) |
|
|
% (self.product_template_id.id, self.product_template_id.name) |
|
|
) |
|
|
) |