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

Delta Between Two Patch Sets: stock.py

Issue 2179041: New module account_stock_anglo_saxon (Closed)
Left Patch Set: Created 14 years, 7 months ago
Right Patch Set: Refactoring: base the code on supplier/customer instead of input/output Created 14 years, 3 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:
Right: Side by side diff | Download
« no previous file with change/comment | « setup.py ('k') | tests/__init__.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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.
3 from decimal import Decimal
4 from trytond.model import ModelView, ModelSQL, fields
5 from trytond.pyson import Eval
6
7
8 class Move(ModelSQL, ModelView):
9 _name = 'stock.move'
10 anglo_saxon_quantity = fields.Float('Anglo-Saxon Quantity',
11 digits=(16, Eval('unit_digits', 2)))
12
13 def __init__(self):
14 super(Move, self).__init__()
15 self._sql_constraints += [
16 ('check_anglo_saxon_quantity',
17 'CHECK(quantity >= anglo_saxon_quantity)',
18 'Anglo-Saxon quantity can not be greater than quantity!'),
19 ]
20
21 def default_anglo_saxon_quantity(self):
22 return 0.0
23
24 def _get_anglo_saxon_move(self, moves, quantity):
25 '''
26 Generator of (move, qty) where move is the move to be consumed and qty
27 is the quantity (in the product default uom) to be consumed on this
28 move.
29 '''
30 uom_obj = self.pool.get('product.uom')
31
32 consumed_qty = 0.0
33 for move in moves:
34 qty = uom_obj.compute_qty(move.uom,
35 move.quantity - move.anglo_saxon_quantity,
36 move.product.default_uom, round=False)
37 if qty <= 0.0:
38 continue
39 if qty > quantity - consumed_qty:
40 qty = quantity - consumed_qty
41 if consumed_qty >= quantity:
42 break
43 yield (move, qty)
44
45 def update_anglo_saxon_quantity_product_cost(self, product, moves,
46 quantity, uom, type_):
47 '''
48 Return the cost for quantity based on lines.
49 Update anglo_saxon_quantity on the concerned moves.
50 '''
51 uom_obj = self.pool.get('product.uom')
52
53 for move in moves:
54 assert move.product == product, 'wrong product'
55 assert type_.startswith('in_') or type_.startswith('out_'), 'wrong type'
56
57 total_qty = uom_obj.compute_qty(uom, quantity, product.default_uom,
58 round=False)
59
60 cost = Decimal('0.0')
61 consumed_qty = 0.0
62 for move, move_qty in self._get_anglo_saxon_move(moves, total_qty):
63 consumed_qty += move_qty
64
65 if type_.startswith('in_'):
66 move_cost_price = uom_obj.compute_price(move.uom,
67 move.unit_price, move.product.default_uom)
68 else:
69 move_cost_price = move.cost_price
70 cost += move_cost_price * Decimal(str(move_qty))
71
72 self.write(move.id, {
73 'anglo_saxon_quantity': ((move.anglo_saxon_quantity or 0.0)
74 + move_qty),
75 })
76
77 if consumed_qty < total_qty:
78 qty = total_qty - consumed_qty
79 consumed_qty += qty
80 cost += product.cost_price * Decimal(str(qty))
81 return cost
82
83 Move()
LEFTRIGHT

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