Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(410)

Unified Diff: product.py

Issue 4306055: New production module (Closed)
Patch Set: To be sure Created 11 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « doc/index.rst ('k') | product.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: product.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/product.py
@@ -0,0 +1,70 @@
+#This file is part of Tryton. The COPYRIGHT file at the top level of
+#this repository contains the full copyright notices and license terms.
+from trytond.model import ModelView, ModelSQL, fields
+from trytond.pyson import Eval, Get, If, Bool
+
+
+class Product(ModelSQL, ModelView):
+ _name = 'product.product'
+
+ boms = fields.One2Many('product.product-production.bom', 'product',
+ 'BOMs', order=[('sequence', 'ASC'), ('id', 'ASC')])
+
+ def __init__(self):
+ super(Product, self).__init__()
+ self._constraints += [
+ ('check_bom_recursion', 'recursive_bom'),
+ ]
+ self._error_messages.update({
+ 'recursive_bom': 'You can not create recursive BOMs!',
+ })
+
+ def check_bom_recursion(self, ids):
+ '''
+ Check BOM recursion
+ '''
+ def check(sub_product, product):
+ for product_bom in sub_product.boms:
+ for input in product_bom.bom.inputs:
+ if input.product == product:
+ return False
+ if not check(input.product, product):
+ return False
+ return True
+ for product in self.browse(ids):
+ if not check(product, product):
+ return False
+ return True
+
+Product()
+
+
+class ProductBom(ModelSQL, ModelView):
+ 'Product - BOM'
+ _name = 'product.product-production.bom'
+ _description = __doc__
+
+ product = fields.Many2One('product.product', 'Product',
+ ondelete='CASCADE', select=1, required=True)
+ bom = fields.Many2One('production.bom', 'BOM', ondelete='CASCADE',
+ select=1, required=True, domain=[
+ ('output_products', '=', If(Bool(Eval('product')),
+ Eval('product', 0),
+ Get(Eval('_parent_product', {}), 'id', 0))),
+ ], depends=['product'])
+ sequence = fields.Integer('Sequence')
+
+ def __init__(self):
+ super(ProductBom, self).__init__()
+ self._order.insert(0, ('sequence', 'ASC'))
+
+ def get_rec_name(self, ids, name):
+ result = {}
+ for product_bom in self.browse(ids):
+ result[product_bom.id] = product_bom.bom.rec_name
+ return result
+
+ def search_rec_name(self, name, clause):
+ return [('bom.rec_name',) + clause[1:]]
+
+ProductBom()
« no previous file with comments | « doc/index.rst ('k') | product.xml » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b