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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
23 additions and
8 deletions
-
purchase_order_generator/__manifest__.py
-
purchase_order_generator/models/product_template.py
-
purchase_order_generator/models/purchase_order_generator.py
-
purchase_order_generator/tests/test_pog.py
-
purchase_order_generator/views/purchase_order_generator.xml
|
|
@ -4,7 +4,7 @@ |
|
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|
|
|
{ |
|
|
|
"name": "Purchase Order Generator", |
|
|
|
"version": "12.0.1.0.0", |
|
|
|
"version": "12.0.2.0.0", |
|
|
|
"category": "Purchase Order", |
|
|
|
"summary": "Generate purchase order from a product selection", |
|
|
|
"author": "Coop IT Easy SCRLfs", |
|
|
|
|
|
@ -8,6 +8,12 @@ from datetime import date |
|
|
|
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): |
|
|
|
_inherit = "product.template" |
|
|
|
|
|
|
|
|
|
@ -71,7 +71,7 @@ class PurchaseOrderGenerator(models.Model): |
|
|
|
) |
|
|
|
|
|
|
|
@api.model |
|
|
|
def generate_cpo(self): |
|
|
|
def test_generate_pog(self): |
|
|
|
order_line_obj = self.env["purchase.order.generator.line"] |
|
|
|
product_ids = self.env.context.get("active_ids", []) |
|
|
|
|
|
|
@ -84,8 +84,17 @@ class PurchaseOrderGenerator(models.Model): |
|
|
|
[ |
|
|
|
("product_tmpl_id", "=", product_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 |
|
|
|
order_line_obj.create( |
|
|
|
{ |
|
|
|
|
|
@ -15,7 +15,7 @@ class TestCPO(TransactionCase): |
|
|
|
self.pproduct2 = self.browse_ref("product.product_delivery_02") |
|
|
|
self.ptemplate2 = self.pproduct2.product_tmpl_id |
|
|
|
|
|
|
|
def test_generate_cpo(self): |
|
|
|
def test_generate_pog(self): |
|
|
|
supplierinfo_obj = self.env["product.supplierinfo"] |
|
|
|
supplierinfo = supplierinfo_obj.search( |
|
|
|
[ |
|
|
@ -33,7 +33,7 @@ class TestCPO(TransactionCase): |
|
|
|
pog_obj = self.env["purchase.order.generator"] |
|
|
|
pog_action = pog_obj.with_context( |
|
|
|
active_ids=[self.ptemplate1.id] |
|
|
|
).generate_cpo() |
|
|
|
).test_generate_pog() |
|
|
|
pog = pog_obj.browse(pog_action["res_id"]) |
|
|
|
pogl = pog.pog_line_ids # expect one line |
|
|
|
|
|
|
@ -66,7 +66,7 @@ class TestCPO(TransactionCase): |
|
|
|
cpo_obj = self.env["purchase.order.generator"] |
|
|
|
cpo_action = cpo_obj.with_context( |
|
|
|
active_ids=[self.ptemplate1.id, self.ptemplate2.id] |
|
|
|
).generate_cpo() |
|
|
|
).test_generate_pog() |
|
|
|
cpo = cpo_obj.browse(cpo_action["res_id"]) |
|
|
|
po_action = cpo.create_purchase_order() |
|
|
|
po = self.env["purchase.order"].browse(po_action["res_id"]) |
|
|
|
|
|
@ -101,13 +101,13 @@ |
|
|
|
|
|
|
|
<!-- 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="model_id" ref="model_purchase_order_generator"/> |
|
|
|
<field name="binding_model_id" ref="product.model_product_template"/> |
|
|
|
<field name="state">code</field> |
|
|
|
<field name="code"> |
|
|
|
action = model.generate_cpo() |
|
|
|
action = model.test_generate_pog() |
|
|
|
</field> |
|
|
|
</record> |
|
|
|
</odoo> |