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

Delta Between Two Patch Sets: bom.py

Issue 4306055: New production module (Closed)
Left Patch Set: Fix order of import Created 13 years, 1 month ago
Right Patch Set: To be sure Created 12 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « __tryton__.py ('k') | bom.xml » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #This file is part of Tryton. The COPYRIGHT file at the top level of 1 #This file is part of Tryton. The COPYRIGHT file at the top level of
2 #this repository contains the full copyright notices and license terms. 2 #this repository contains the full copyright notices and license terms.
3 from trytond.model import ModelView, ModelSQL, fields 3 from trytond.model import ModelView, ModelSQL, fields
4 from trytond.wizard import Wizard 4 from trytond.wizard import Wizard, StateView, Button
5 from trytond.transaction import Transaction
5 from trytond.pyson import Eval 6 from trytond.pyson import Eval
6 from trytond.pool import Pool 7 from trytond.pool import Pool
7 8
8 9
9 class BOM(ModelSQL, ModelView): 10 class BOM(ModelSQL, ModelView):
10 "Bill of Material" 11 "Bill of Material"
11 _name = 'production.bom' 12 _name = 'production.bom'
12 _description = __doc__ 13 _description = __doc__
13 14
14 name = fields.Char('Name', required=True, translate=True) 15 name = fields.Char('Name', required=True, translate=True)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 super(BOMInput, self).__init__() 73 super(BOMInput, self).__init__()
73 self._sql_constraints = [ 74 self._sql_constraints = [
74 ('product_bom_uniq', 'UNIQUE(product, bom)', 75 ('product_bom_uniq', 'UNIQUE(product, bom)',
75 'product_bom_uniq'), 76 'product_bom_uniq'),
76 ] 77 ]
77 self._constraints += [ 78 self._constraints += [
78 ('check_bom_recursion', 'recursive_bom'), 79 ('check_bom_recursion', 'recursive_bom'),
79 ] 80 ]
80 self._error_messages.update({ 81 self._error_messages.update({
81 'product_bom_uniq': 'Product must be unique per BOM!', 82 'product_bom_uniq': 'Product must be unique per BOM!',
82 'recursive_bom': 'You can not create recursive boms!', 83 'recursive_bom': 'You can not create recursive BOMs!',
83 }) 84 })
84 85
85 def on_change_product(self, vals): 86 def on_change_product(self, vals):
86 product_obj = Pool().get('product.product') 87 product_obj = Pool().get('product.product')
87 88
88 res = {} 89 res = {}
89 if vals.get('product'): 90 if vals.get('product'):
90 product = product_obj.browse(vals['product']) 91 product = product_obj.browse(vals['product'])
91 uom_ids = [x.id for x in product.default_uom.category.uoms] 92 uom_ids = [x.id for x in product.default_uom.category.uoms]
92 if (not vals.get('uom') 93 if (not vals.get('uom')
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return product_obj.check_bom_recursion(product_ids) 138 return product_obj.check_bom_recursion(product_ids)
138 139
139 def compute_quantity(self, line, factor): 140 def compute_quantity(self, line, factor):
140 uom_obj = Pool().get('product.uom') 141 uom_obj = Pool().get('product.uom')
141 return uom_obj.round(line.quantity * factor, line.uom.rounding) 142 return uom_obj.round(line.quantity * factor, line.uom.rounding)
142 143
143 BOMInput() 144 BOMInput()
144 145
145 146
146 class BOMOutput(BOMInput): 147 class BOMOutput(BOMInput):
147 "Bill of Material OutPut" 148 "Bill of Material Output"
148 _name = 'production.bom.output' 149 _name = 'production.bom.output'
149 _description = __doc__ 150 _description = __doc__
150 151
151 BOMOutput() 152 BOMOutput()
152 153
153 154
154 class BOMTree(ModelView): 155 class BOMTree(ModelView):
155 'BOM Tree' 156 'BOM Tree'
156 _name = 'production.bom.tree' 157 _name = 'production.bom.tree'
157 _description = __doc__ 158 _description = __doc__
(...skipping 25 matching lines...) Expand all
183 'uom': input.uom.id, 184 'uom': input.uom.id,
184 'unit_digits': input.uom.digits, 185 'unit_digits': input.uom.digits,
185 'childs': childs, 186 'childs': childs,
186 } 187 }
187 result.append(values) 188 result.append(values)
188 return result 189 return result
189 190
190 BOMTree() 191 BOMTree()
191 192
192 193
193 class OpenBOMTreeInit(ModelView): 194 class OpenBOMTreeStart(ModelView):
194 'Open BOM Tree Init' 195 'Open BOM Tree'
195 _name = 'production.bom.tree.open.init' 196 _name = 'production.bom.tree.open.start'
196 197
197 quantity = fields.Float('Quantity', required=True, 198 quantity = fields.Float('Quantity', required=True,
198 digits=(16, Eval('unit_digits', 2)), depends=['unit_digits']) 199 digits=(16, Eval('unit_digits', 2)), depends=['unit_digits'])
199 uom = fields.Many2One('product.uom', 'Unit', required=True, 200 uom = fields.Many2One('product.uom', 'Unit', required=True,
200 domain=[ 201 domain=[
201 ('category', '=', Eval('category')), 202 ('category', '=', Eval('category')),
202 ], depends=['category']) 203 ], depends=['category'])
203 unit_digits = fields.Integer('Unit Digits', readonly=True, 204 unit_digits = fields.Integer('Unit Digits', readonly=True,
204 on_change_with=['uom']) 205 on_change_with=['uom'])
205 category = fields.Many2One('product.uom.category', 'Category', 206 category = fields.Many2One('product.uom.category', 'Category',
206 readonly=True) 207 readonly=True)
207 bom = fields.Many2One('product.product-production.bom', 208 bom = fields.Many2One('product.product-production.bom',
208 'BOM', required=True, domain=[ 209 'BOM', required=True, domain=[
209 ('product', '=', Eval('product')), 210 ('product', '=', Eval('product')),
210 ], depends=['product']) 211 ], depends=['product'])
211 product = fields.Many2One('product.product', 'Product', readonly=True) 212 product = fields.Many2One('product.product', 'Product', readonly=True)
212 213
213 def on_change_with_unit_digits(self, values): 214 def on_change_with_unit_digits(self, values):
214 uom_obj = Pool().get('product.uom') 215 uom_obj = Pool().get('product.uom')
215 if values.get('uom'): 216 if values.get('uom'):
216 uom = uom_obj.browse(values['uom']) 217 uom = uom_obj.browse(values['uom'])
217 return uom.digits 218 return uom.digits
218 return 2 219 return 2
219 220
220 OpenBOMTreeInit() 221 OpenBOMTreeStart()
221 222
222 223
223 class OpenBOMTreeTree(ModelView): 224 class OpenBOMTreeTree(ModelView):
224 'Open BOM Tree Tree' 225 'Open BOM Tree'
225 _name = 'production.bom.tree.open.tree' 226 _name = 'production.bom.tree.open.tree'
226 227
227 bom_tree = fields.One2Many('production.bom.tree', None, 'BOM Tree') 228 bom_tree = fields.One2Many('production.bom.tree', None, 'BOM Tree')
228 229
229 def tree(self, bom_id, product_id, quantity, uom_id): 230 def tree(self, bom, product, quantity, uom):
230 pool = Pool() 231 pool = Pool()
231 tree_obj = pool.get('production.bom.tree') 232 tree_obj = pool.get('production.bom.tree')
232 bom_obj = pool.get('production.bom') 233
233 product_obj = pool.get('product.product')
234 uom_obj = pool.get('product.uom')
235
236 bom = bom_obj.browse(bom_id)
237 product = product_obj.browse(product_id)
238 uom = uom_obj.browse(uom_id)
239 childs = tree_obj.tree(product, quantity, uom, bom=bom) 234 childs = tree_obj.tree(product, quantity, uom, bom=bom)
240 bom_tree = [{ 235 bom_tree = [{
241 'product': product_id, 236 'product': product.id,
242 'quantity': quantity, 237 'quantity': quantity,
243 'uom': uom_id, 238 'uom': uom.id,
244 'unit_digits': uom.digits, 239 'unit_digits': uom.digits,
245 'childs': childs, 240 'childs': childs,
246 }] 241 }]
247 return { 242 return {
248 'bom_tree': bom_tree, 243 'bom_tree': bom_tree,
249 } 244 }
250 245
251 OpenBOMTreeTree() 246 OpenBOMTreeTree()
252 247
253 248
254 class OpenBOMTree(Wizard): 249 class OpenBOMTree(Wizard):
255 'Open BOM Tree' 250 'Open BOM Tree'
256 _name = 'production.bom.tree.open' 251 _name = 'production.bom.tree.open'
257 252
258 states = { 253 start = StateView('production.bom.tree.open.start',
259 'init': { 254 'production.bom_tree_open_start_view_form', [
260 'actions': ['_init'], 255 Button('Cancel', 'end', 'tryton-cancel'),
261 'result': { 256 Button('Ok', 'tree', 'tryton-ok', True),
262 'type': 'form', 257 ])
263 'object': 'production.bom.tree.open.init', 258 tree = StateView('production.bom.tree.open.tree',
264 'state': [ 259 'production.bom_tree_open_tree_view_form', [
265 ('end', 'Cancel', 'tryton-cancel'), 260 Button('Change', 'start', 'tryton-go-previous'),
266 ('tree', 'Ok', 'tryton-ok', True), 261 Button('Close', 'end', 'tryton-close'),
267 ], 262 ])
268 }, 263
269 }, 264 def default_start(self, session, fields):
270 'tree': { 265 product_obj = Pool().get('product.product')
271 'actions': ['_tree'], 266 defaults = {}
272 'result': { 267 product = product_obj.browse(Transaction().context['active_id'])
273 'type': 'form', 268 defaults['category'] = product.default_uom.category.id
274 'object': 'production.bom.tree.open.tree', 269 if session.start.uom:
275 'state': [ 270 defaults['uom'] = session.start.uom.id
276 ('init', 'Change', 'tryton-go-previous'), 271 defaults['unit_digits'] = session.start.unit_digits
277 ('end', 'Close', 'tryton-close', True), 272 else:
278 ], 273 defaults['uom'] = product.default_uom.id
279 }, 274 defaults['unit_digits'] = product.default_uom.digits
280 }, 275 defaults['product'] = product.id
281 } 276 if session.start.bom:
282 277 defaults['bom'] = session.start.bom.id
283 def _init(self, data): 278 elif product.boms:
284 product_obj = Pool().get('product.product') 279 defaults['bom'] = product.boms[0].id
285 result = {} 280 defaults['quantity'] = session.start.quantity
286 product = product_obj.browse(data['id']) 281 return defaults
287 result['category'] = product.default_uom.category.id 282
288 result['uom'] = product.default_uom.id 283 def default_tree(self, session, fields):
289 result['unit_digits'] = product.default_uom.digits 284 pool = Pool()
290 result['product'] = product.id 285 bom_tree_obj = pool.get('production.bom.tree.open.tree')
291 if product.boms: 286 return bom_tree_obj.tree(session.start.bom.bom, session.start.product,
292 result['bom'] = product.boms[0].id 287 session.start.quantity, session.start.uom)
293 return result
294
295 def _tree(self, data):
296 bom_tree_obj = Pool().get('production.bom.tree.open.tree')
297 return bom_tree_obj.tree(data['form']['bom'], data['id'],
298 data['form']['quantity'], data['form']['uom'])
299 288
300 OpenBOMTree() 289 OpenBOMTree()
LEFTRIGHT

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