Merge lp:~savoirfairelinux-openerp/sale-wkfl/sale_lot_tracking into lp:~sale-core-editors/sale-wkfl/7.0

Status: Needs review
Proposed branch: lp:~savoirfairelinux-openerp/sale-wkfl/sale_lot_tracking
Merge into: lp:~sale-core-editors/sale-wkfl/7.0
Diff against target: 213 lines (+197/-0)
3 files modified
sale_lot_tracking/__init__.py (+23/-0)
sale_lot_tracking/__openerp__.py (+51/-0)
sale_lot_tracking/sale.py (+123/-0)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/sale-wkfl/sale_lot_tracking
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Resubmitting
Review via email: mp+216323@code.launchpad.net

Commit message

[ADD] sale_lot_tracking

Description of the change

[ADD] sale_lot_tracking

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

This project is now hosted on https://github.com/OCA/sale-workflow. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting

Unmerged revisions

29. By David Cormier

[FIX] remove pdb

28. By David Cormier

[FIX] Fix landed costs calculation when stock is picked from different lots

27. By David Cormier

[NEW] Add writeoff lot tracking

26. By David Cormier

[NEW] Initial commit of sale_lot_tracking

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'sale_lot_tracking'
2=== added file 'sale_lot_tracking/README'
3=== added file 'sale_lot_tracking/__init__.py'
4--- sale_lot_tracking/__init__.py 1970-01-01 00:00:00 +0000
5+++ sale_lot_tracking/__init__.py 2014-04-17 13:51:05 +0000
6@@ -0,0 +1,23 @@
7+# -*- coding: utf-8 -*-
8+##############################################################################
9+#
10+# OpenERP, Open Source Management Solution
11+# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
12+#
13+# This program is free software: you can redistribute it and/or modify
14+# it under the terms of the GNU Affero General Public License as
15+# published by the Free Software Foundation, either version 3 of the
16+# License, or (at your option) any later version.
17+#
18+# This program is distributed in the hope that it will be useful,
19+# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+# GNU Affero General Public License for more details.
22+#
23+# You should have received a copy of the GNU Affero General Public License
24+# along with this program. If not, see <http://www.gnu.org/licenses/>.
25+#
26+##############################################################################
27+
28+import sale
29+
30
31=== added file 'sale_lot_tracking/__openerp__.py'
32--- sale_lot_tracking/__openerp__.py 1970-01-01 00:00:00 +0000
33+++ sale_lot_tracking/__openerp__.py 2014-04-17 13:51:05 +0000
34@@ -0,0 +1,51 @@
35+# -*- coding: utf-8 -*-
36+##############################################################################
37+#
38+# OpenERP, Open Source Management Solution
39+# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
40+#
41+# This program is free software: you can redistribute it and/or modify
42+# it under the terms of the GNU Affero General Public License as
43+# published by the Free Software Foundation, either version 3 of the
44+# License, or (at your option) any later version.
45+#
46+# This program is distributed in the hope that it will be useful,
47+# but WITHOUT ANY WARRANTY; without even the implied warranty of
48+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49+# GNU Affero General Public License for more details.
50+#
51+# You should have received a copy of the GNU Affero General Public License
52+# along with this program. If not, see <http://www.gnu.org/licenses/>.
53+#
54+##############################################################################
55+
56+# NOTE: The name of the supplied field was initially "display_name", but it seems that OpenERP,
57+# whenever it seems "name" in the field, returns the value for "name". Well...
58+
59+{
60+ 'name': 'sale_lot_tracking',
61+ 'version': '1.0',
62+ 'author': 'Savoir-faire Linux',
63+ 'website': 'http://www.savoirfairelinux.com',
64+ 'category': 'Generic Modules/Purchases',
65+ 'description': """
66+Lets you track sales using product's lots numbers
67+====================================================
68+
69+This module lets you track sales using a product's lot
70+number.
71+
72+
73+""",
74+ 'depends': ['base',
75+ 'sale_landed_costs',
76+ 'purchase_landed_costs',
77+ 'analytic'],
78+ 'data': [
79+
80+ ],
81+ 'demo': [],
82+ 'test': [],
83+ 'installable': True,
84+ 'active': False,
85+}
86
87=== added file 'sale_lot_tracking/sale.py'
88--- sale_lot_tracking/sale.py 1970-01-01 00:00:00 +0000
89+++ sale_lot_tracking/sale.py 2014-04-17 13:51:05 +0000
90@@ -0,0 +1,123 @@
91+# -*- coding: utf-8 -*-
92+##############################################################################
93+#
94+# OpenERP, Open Source Management Solution
95+# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
96+#
97+# This program is free software: you can redistribute it and/or modify
98+# it under the terms of the GNU Affero General Public License as
99+# published by the Free Software Foundation, either version 3 of the
100+# License, or (at your option) any later version.
101+#
102+# This program is distributed in the hope that it will be useful,
103+# but WITHOUT ANY WARRANTY; without even the implied warranty of
104+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105+# GNU Affero General Public License for more details.
106+#
107+# You should have received a copy of the GNU Affero General Public License
108+# along with this program. If not, see <http://www.gnu.org/licenses/>.
109+#
110+##############################################################################
111+
112+from openerp.osv import orm, fields
113+import logging
114+
115+class sale_order(orm.Model):
116+
117+ _inherit = 'sale.order'
118+ _logger = logging.Logger(__name__)
119+
120+ def _create_pickings(self, cr, uid, order, context=None):
121+
122+ sale_order_lines = order.order_line
123+ stock_move_obj = self.pool.get('stock.move')
124+ stock_move_line_ids = stock_move_obj.search(cr, uid, [('origin', '=', order.name)])
125+ stock_move_lines = stock_move_obj.browse(cr, uid, stock_move_line_ids)
126+
127+
128+
129+ invoice_obj = self.pool.get('account.invoice')
130+ invoice_line_obj = self.pool.get('account.invoice.line')
131+ journal_obj = self.pool.get('account.journal')
132+ journal_ids = journal_obj.search(cr, uid, [('type', '=', 'purchase'),
133+ ('company_id', '=', order.company_id.id)],
134+ limit=1)
135+
136+ total_pallets = 0.0
137+
138+ for so_line in order.order_line:
139+ total_pallets += so_line.nb_pallets
140+
141+
142+ for order_cost in order.landed_cost_line_ids:
143+ vals_inv = {
144+ 'partner_id': order_cost.partner_id.id,
145+ 'currency_id': order_cost.currency_id.id or order.company_id.currency_id.id,
146+ 'account_id': order_cost.partner_id.property_account_payable.id,
147+ 'type': 'in_invoice',
148+ 'origin': order.name,
149+ 'fiscal_position': (order.partner_id.property_account_position and
150+ order.partner_id.property_account_position.id or
151+ False),
152+ 'company_id': order.company_id.id,
153+ 'journal_id': len(journal_ids) and journal_ids[0] or False
154+ }
155+
156+ inv_id = invoice_obj.create(cr, uid, vals_inv, context=None)
157+
158+ for sale_order_line in sale_order_lines:
159+
160+ factor = 0.0
161+
162+ if order_cost.price_type == 'per_unit':
163+ factor = float(sale_order_line.product_uom_qty) / sale_order_line.order_id.quantity_total
164+
165+ elif order_cost.price_type == 'value':
166+ factor = float(sale_order_line.price_subtotal) / sale_order_line.order_id.amount_total
167+
168+ elif order_cost.price_type == 'per_pallet':
169+ #FIXME: total_pallets
170+ factor = float(sale_order_line.nb_pallets) / total_pallets
171+
172+ else:
173+ raise ValueError('Unknown price type (neither "per_unit", "value" nor "per_pallet")')
174+
175+ amount = order_cost.amount * factor
176+
177+ # trouver le compte analytique
178+ # FIXME: ne pas uniquement regarder la quantité
179+
180+
181+
182+ # répercuter sur l'ensemble des lots
183+
184+ matching_lines = [
185+ line
186+ for line in stock_move_lines
187+ if line.product_id.id == sale_order_line.product_id.id
188+ ]
189+
190+ for line in matching_lines:
191+ total_product = sum(l.product_qty for l in matching_lines)
192+ amount_line = amount * (line.product_qty / total_product)
193+
194+ # fractionner les coûts
195+
196+ vals_line = {
197+ 'product_id': order_cost.product_id.id,
198+ 'name': order_cost.product_id.name,
199+ 'account_id': self._get_product_account_expense_id(order_cost.product_id),
200+ 'partner_id': order_cost.partner_id.id,
201+ 'invoice_id': inv_id,
202+ 'price_unit': amount,
203+ 'account_analytic_id': line.prodlot_id.account_analytic_id.id,
204+ 'invoice_line_tax_id': [(6, 0, [x.id for x in order_cost.product_id.supplier_taxes_id])]
205+ }
206+
207+ invoice_line_obj.create(cr, uid, vals_line, context=None)
208+
209+
210+
211+
212+
213+

Subscribers

People subscribed via source and target branches