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
=== added directory 'sale_lot_tracking'
=== added file 'sale_lot_tracking/README'
=== added file 'sale_lot_tracking/__init__.py'
--- sale_lot_tracking/__init__.py 1970-01-01 00:00:00 +0000
+++ sale_lot_tracking/__init__.py 2014-04-17 13:51:05 +0000
@@ -0,0 +1,23 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22import sale
23
024
=== added file 'sale_lot_tracking/__openerp__.py'
--- sale_lot_tracking/__openerp__.py 1970-01-01 00:00:00 +0000
+++ sale_lot_tracking/__openerp__.py 2014-04-17 13:51:05 +0000
@@ -0,0 +1,51 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22# NOTE: The name of the supplied field was initially "display_name", but it seems that OpenERP,
23# whenever it seems "name" in the field, returns the value for "name". Well...
24
25{
26 'name': 'sale_lot_tracking',
27 'version': '1.0',
28 'author': 'Savoir-faire Linux',
29 'website': 'http://www.savoirfairelinux.com',
30 'category': 'Generic Modules/Purchases',
31 'description': """
32Lets you track sales using product's lots numbers
33====================================================
34
35This module lets you track sales using a product's lot
36number.
37
38
39""",
40 'depends': ['base',
41 'sale_landed_costs',
42 'purchase_landed_costs',
43 'analytic'],
44 'data': [
45
46 ],
47 'demo': [],
48 'test': [],
49 'installable': True,
50 'active': False,
51}
052
=== added file 'sale_lot_tracking/sale.py'
--- sale_lot_tracking/sale.py 1970-01-01 00:00:00 +0000
+++ sale_lot_tracking/sale.py 2014-04-17 13:51:05 +0000
@@ -0,0 +1,123 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# Copyright (C) 2013 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21
22from openerp.osv import orm, fields
23import logging
24
25class sale_order(orm.Model):
26
27 _inherit = 'sale.order'
28 _logger = logging.Logger(__name__)
29
30 def _create_pickings(self, cr, uid, order, context=None):
31
32 sale_order_lines = order.order_line
33 stock_move_obj = self.pool.get('stock.move')
34 stock_move_line_ids = stock_move_obj.search(cr, uid, [('origin', '=', order.name)])
35 stock_move_lines = stock_move_obj.browse(cr, uid, stock_move_line_ids)
36
37
38
39 invoice_obj = self.pool.get('account.invoice')
40 invoice_line_obj = self.pool.get('account.invoice.line')
41 journal_obj = self.pool.get('account.journal')
42 journal_ids = journal_obj.search(cr, uid, [('type', '=', 'purchase'),
43 ('company_id', '=', order.company_id.id)],
44 limit=1)
45
46 total_pallets = 0.0
47
48 for so_line in order.order_line:
49 total_pallets += so_line.nb_pallets
50
51
52 for order_cost in order.landed_cost_line_ids:
53 vals_inv = {
54 'partner_id': order_cost.partner_id.id,
55 'currency_id': order_cost.currency_id.id or order.company_id.currency_id.id,
56 'account_id': order_cost.partner_id.property_account_payable.id,
57 'type': 'in_invoice',
58 'origin': order.name,
59 'fiscal_position': (order.partner_id.property_account_position and
60 order.partner_id.property_account_position.id or
61 False),
62 'company_id': order.company_id.id,
63 'journal_id': len(journal_ids) and journal_ids[0] or False
64 }
65
66 inv_id = invoice_obj.create(cr, uid, vals_inv, context=None)
67
68 for sale_order_line in sale_order_lines:
69
70 factor = 0.0
71
72 if order_cost.price_type == 'per_unit':
73 factor = float(sale_order_line.product_uom_qty) / sale_order_line.order_id.quantity_total
74
75 elif order_cost.price_type == 'value':
76 factor = float(sale_order_line.price_subtotal) / sale_order_line.order_id.amount_total
77
78 elif order_cost.price_type == 'per_pallet':
79 #FIXME: total_pallets
80 factor = float(sale_order_line.nb_pallets) / total_pallets
81
82 else:
83 raise ValueError('Unknown price type (neither "per_unit", "value" nor "per_pallet")')
84
85 amount = order_cost.amount * factor
86
87 # trouver le compte analytique
88 # FIXME: ne pas uniquement regarder la quantité
89
90
91
92 # répercuter sur l'ensemble des lots
93
94 matching_lines = [
95 line
96 for line in stock_move_lines
97 if line.product_id.id == sale_order_line.product_id.id
98 ]
99
100 for line in matching_lines:
101 total_product = sum(l.product_qty for l in matching_lines)
102 amount_line = amount * (line.product_qty / total_product)
103
104 # fractionner les coûts
105
106 vals_line = {
107 'product_id': order_cost.product_id.id,
108 'name': order_cost.product_id.name,
109 'account_id': self._get_product_account_expense_id(order_cost.product_id),
110 'partner_id': order_cost.partner_id.id,
111 'invoice_id': inv_id,
112 'price_unit': amount,
113 'account_analytic_id': line.prodlot_id.account_analytic_id.id,
114 'invoice_line_tax_id': [(6, 0, [x.id for x in order_cost.product_id.supplier_taxes_id])]
115 }
116
117 invoice_line_obj.create(cr, uid, vals_line, context=None)
118
119
120
121
122
123

Subscribers

People subscribed via source and target branches