Browse Source

Merge pull request #174 from beescoop/12.0-fix-gpo

[12.0] fix main supplier selection to make it deterministic
pull/173/head
Robin Keunen 4 years ago
committed by GitHub
parent
commit
db45719067
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      purchase_order_generator/__manifest__.py
  2. 6
      purchase_order_generator/models/product_template.py
  3. 13
      purchase_order_generator/models/purchase_order_generator.py
  4. 6
      purchase_order_generator/tests/test_pog.py
  5. 4
      purchase_order_generator/views/purchase_order_generator.xml

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"

13
purchase_order_generator/models/purchase_order_generator.py

@ -71,7 +71,7 @@ class PurchaseOrderGenerator(models.Model):
) )
@api.model @api.model
def generate_cpo(self):
def test_generate_pog(self):
order_line_obj = self.env["purchase.order.generator.line"] order_line_obj = self.env["purchase.order.generator.line"]
product_ids = self.env.context.get("active_ids", []) product_ids = self.env.context.get("active_ids", [])
@ -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(
{ {

6
purchase_order_generator/tests/test_pog.py

@ -15,7 +15,7 @@ class TestCPO(TransactionCase):
self.pproduct2 = self.browse_ref("product.product_delivery_02") self.pproduct2 = self.browse_ref("product.product_delivery_02")
self.ptemplate2 = self.pproduct2.product_tmpl_id self.ptemplate2 = self.pproduct2.product_tmpl_id
def test_generate_cpo(self):
def test_generate_pog(self):
supplierinfo_obj = self.env["product.supplierinfo"] supplierinfo_obj = self.env["product.supplierinfo"]
supplierinfo = supplierinfo_obj.search( supplierinfo = supplierinfo_obj.search(
[ [
@ -33,7 +33,7 @@ class TestCPO(TransactionCase):
pog_obj = self.env["purchase.order.generator"] pog_obj = self.env["purchase.order.generator"]
pog_action = pog_obj.with_context( pog_action = pog_obj.with_context(
active_ids=[self.ptemplate1.id] active_ids=[self.ptemplate1.id]
).generate_cpo()
).test_generate_pog()
pog = pog_obj.browse(pog_action["res_id"]) pog = pog_obj.browse(pog_action["res_id"])
pogl = pog.pog_line_ids # expect one line pogl = pog.pog_line_ids # expect one line
@ -66,7 +66,7 @@ class TestCPO(TransactionCase):
cpo_obj = self.env["purchase.order.generator"] cpo_obj = self.env["purchase.order.generator"]
cpo_action = cpo_obj.with_context( cpo_action = cpo_obj.with_context(
active_ids=[self.ptemplate1.id, self.ptemplate2.id] active_ids=[self.ptemplate1.id, self.ptemplate2.id]
).generate_cpo()
).test_generate_pog()
cpo = cpo_obj.browse(cpo_action["res_id"]) cpo = cpo_obj.browse(cpo_action["res_id"])
po_action = cpo.create_purchase_order() po_action = cpo.create_purchase_order()
po = self.env["purchase.order"].browse(po_action["res_id"]) po = self.env["purchase.order"].browse(po_action["res_id"])

4
purchase_order_generator/views/purchase_order_generator.xml

@ -101,13 +101,13 @@
<!-- Actions --> <!-- Actions -->
<record id="action_generate_cpo" model="ir.actions.server">
<record id="action_generate_pog" model="ir.actions.server">
<field name="name">Generate Purchase Order</field> <field name="name">Generate Purchase Order</field>
<field name="model_id" ref="model_purchase_order_generator"/> <field name="model_id" ref="model_purchase_order_generator"/>
<field name="binding_model_id" ref="product.model_product_template"/> <field name="binding_model_id" ref="product.model_product_template"/>
<field name="state">code</field> <field name="state">code</field>
<field name="code"> <field name="code">
action = model.generate_cpo()
action = model.test_generate_pog()
</field> </field>
</record> </record>
</odoo> </odoo>
Loading…
Cancel
Save