Browse Source

[FIX] pog: select most recent supplierinfo

pull/174/head
robin.keunen 4 years ago
parent
commit
9e3bac6da0
  1. 2
      purchase_order_generator/__manifest__.py
  2. 6
      purchase_order_generator/models/product_template.py
  3. 11
      purchase_order_generator/models/purchase_order_generator.py

2
purchase_order_generator/__manifest__.py

@ -4,7 +4,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{ {
"name": "Purchase Order Generator", "name": "Purchase Order Generator",
"version": "12.0.1.0.0",
"version": "12.0.2.0.0",
"category": "Purchase Order", "category": "Purchase Order",
"summary": "Generate purchase order from a product selection", "summary": "Generate purchase order from a product selection",
"author": "Coop IT Easy SCRLfs", "author": "Coop IT Easy SCRLfs",

6
purchase_order_generator/models/product_template.py

@ -8,6 +8,12 @@ from datetime import date
from odoo import api, fields, models from odoo import api, fields, models
class SupplierInfo(models.Model):
_inherit = "product.supplierinfo"
date_start = fields.Date(default=fields.Date.context_today, required=True)
class ProductTemplate(models.Model): class ProductTemplate(models.Model):
_inherit = "product.template" _inherit = "product.template"

11
purchase_order_generator/models/purchase_order_generator.py

@ -84,8 +84,17 @@ class PurchaseOrderGenerator(models.Model):
[ [
("product_tmpl_id", "=", product_id), ("product_tmpl_id", "=", product_id),
("name", "=", supplier.id), ("name", "=", supplier.id),
]
],
order="date_start desc",
limit=1,
) )
if not supplierinfo:
product_name = self.env["product.template"].browse(product_id).name
raise ValidationError(
_("No supplier defined for product %s") % product_name
)
min_qty = supplierinfo.min_qty if supplierinfo else 0 min_qty = supplierinfo.min_qty if supplierinfo else 0
order_line_obj.create( order_line_obj.create(
{ {

Loading…
Cancel
Save