Merge lp:~vauxoo/addons-vauxoo/7.0-stock_property_account_product_dev_jorge into lp:addons-vauxoo/7.0

Status: Needs review
Proposed branch: lp:~vauxoo/addons-vauxoo/7.0-stock_property_account_product_dev_jorge
Merge into: lp:addons-vauxoo/7.0
Diff against target: 400 lines (+373/-0)
5 files modified
stock_valuation_account_product/__init__.py (+23/-0)
stock_valuation_account_product/__openerp__.py (+51/-0)
stock_valuation_account_product/model/__init__.py (+23/-0)
stock_valuation_account_product/model/product_product.py (+256/-0)
stock_valuation_account_product/view/product_product_stock_valuation_account.xml (+20/-0)
To merge this branch: bzr merge lp:~vauxoo/addons-vauxoo/7.0-stock_property_account_product_dev_jorge
Reviewer Review Type Date Requested Status
Moisés López - http://www.vauxoo.com Needs Fixing
Jorge Angel Naranjo Rogel - http://www.vauxoo.com Needs Resubmitting
Jose Antonio Morales Ponce(vauxoo) - - http://www.vauxoo.com Needs Fixing
Rodolfo Lopez Pending
Review via email: mp+185370@code.launchpad.net

Description of the change

Se crea modulo para agregar el campo property de valoración inventario en el producto. Ademas se modifica la función que genera la poliza de valoración de inventario, que tome como prioridad la cuenta de valoración de inventario del producto y después la de la categoría en caso de que el producto no tenga.

To post a comment you must log in.
Revision history for this message
Jose Antonio Morales Ponce(vauxoo) - - http://www.vauxoo.com (josemoralesp) wrote :

El modulo ya tiene traduccion?

review: Needs Fixing
Revision history for this message
Jorge Angel Naranjo Rogel - http://www.vauxoo.com (jorge-nr) wrote :

Si el property ya tiene traducción por eso no agrege esa parte.

review: Needs Resubmitting
Revision history for this message
Moisés López - http://www.vauxoo.com (moylop260) wrote :

@Jorge,
En lo personal no me gusta nada que sea "Method overriding"
Sin embargo, donde no hay otra opción, pues se hace.
Aunque también tenemos la via del "parche", que tampoco es la mejor opción.
O un branch paralelo al nativo, para agregar esta funcionalidad, y que se haga el merge en nuestros branches, e incluso lo proponemos para que OpenERP lo considere dentro de sus cambios.

Otra opción, es hacer un análisis de estas funciones para separar la preparación de los diccionarios (como hace stock.py), para que se puedan heredar fácilmente.

Otra opción (que en lo personal, no me gusta tampoco), para marearte más, es como lo hace el módulo de anglosaxon, que modifica la póliza una vez creada.

En resumen, vamos a tomar el siguiente camino:
-Hacer un branch clone de openobject-addons para agregar la parte que necesitamos.
-Reportar un bug (tipo wishlist) con el tema de que no están dejando heredable esta parte.

review: Needs Fixing

Unmerged revisions

802. By Jorge Angel Naranjo Rogel - http://www.vauxoo.com

[IMP][stock_valuation_account_product] Depends account_anglo_saxon

801. By Jorge Angel Naranjo Rogel - http://www.vauxoo.com

[IMP][stock_valuation_account_product] Delete function load_valuation_items and prints

800. By Jorge Angel Naranjo Rogel - http://www.vauxoo.com

[ADD][stock_valuation_account_product] This module added in form view of product in the seccion Accounting the field Stock Valuation Account

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'stock_valuation_account_product'
=== added file 'stock_valuation_account_product/__init__.py'
--- stock_valuation_account_product/__init__.py 1970-01-01 00:00:00 +0000
+++ stock_valuation_account_product/__init__.py 2013-09-12 21:23:37 +0000
@@ -0,0 +1,23 @@
1#!/usr/bin/python
2# -*- encoding: utf-8 -*-
3#
4# Module Writen to OpenERP, Open Source Management Solution
5# Copyright (C) Vauxoo (<http://vauxoo.com>).
6# All Rights Reserved
7#
8# Coded by: Jorge Angel Naranjo Rogel (jorge_nr@vauxoo.com)
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU Affero General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU Affero General Public License for more details.
19#
20# You should have received a copy of the GNU Affero General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
23import model
024
=== added file 'stock_valuation_account_product/__openerp__.py'
--- stock_valuation_account_product/__openerp__.py 1970-01-01 00:00:00 +0000
+++ stock_valuation_account_product/__openerp__.py 2013-09-12 21:23:37 +0000
@@ -0,0 +1,51 @@
1#!/usr/bin/python
2# -*- encoding: utf-8 -*-
3#
4# Module Writen to OpenERP, Open Source Management Solution
5# Copyright (C) Vauxoo (<http://vauxoo.com>).
6# All Rights Reserved
7#
8# Coded by: Jorge Angel Naranjo Rogel (jorge_nr@vauxoo.com)
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU Affero General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU Affero General Public License for more details.
19#
20# You should have received a copy of the GNU Affero General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
23{
24 "name": "Stock Valuation Account In Product",
25 "version": "1.0",
26 "depends": [
27 "product",
28 "stock",
29 "mrp",
30 "account_anglo_saxon",
31 ],
32 "author": "Vauxoo",
33 "description" : """
34Stock Valuation Account In Product
35====================================
36
37This module added in form view of product in the seccion Accounting
38the field Stock Valuation Account.
39
40 """,
41 "website": "http://vauxoo.com",
42 "category": "Addons Vauxoo",
43 "demo": [],
44 "test": [],
45 "data": [
46 'view/product_product_stock_valuation_account.xml',
47 ],
48 'application': True,
49 "active": False,
50 "installable": True,
51}
052
=== added directory 'stock_valuation_account_product/model'
=== added file 'stock_valuation_account_product/model/__init__.py'
--- stock_valuation_account_product/model/__init__.py 1970-01-01 00:00:00 +0000
+++ stock_valuation_account_product/model/__init__.py 2013-09-12 21:23:37 +0000
@@ -0,0 +1,23 @@
1#!/usr/bin/python
2# -*- encoding: utf-8 -*-
3#
4# Module Writen to OpenERP, Open Source Management Solution
5# Copyright (C) Vauxoo (<http://vauxoo.com>).
6# All Rights Reserved
7#
8# Coded by: Jorge Angel Naranjo Rogel (jorge_nr@vauxoo.com)
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU Affero General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU Affero General Public License for more details.
19#
20# You should have received a copy of the GNU Affero General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
23import product_product
024
=== added file 'stock_valuation_account_product/model/product_product.py'
--- stock_valuation_account_product/model/product_product.py 1970-01-01 00:00:00 +0000
+++ stock_valuation_account_product/model/product_product.py 2013-09-12 21:23:37 +0000
@@ -0,0 +1,256 @@
1#!/usr/bin/python
2# -*- encoding: utf-8 -*-
3#
4# Module Writen to OpenERP, Open Source Management Solution
5# Copyright (C) Vauxoo (<http://vauxoo.com>).
6# All Rights Reserved
7#
8# Coded by: Jorge Angel Naranjo Rogel (jorge_nr@vauxoo.com)
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU Affero General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU Affero General Public License for more details.
19#
20# You should have received a copy of the GNU Affero General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
23from openerp.osv import fields, osv
24from openerp.tools.translate import _
25import datetime
26
27
28class product_product (osv.Model):
29 _inherit = "product.product"
30 _columns = {
31 'property_stock_valuation_account_id': fields.property('account.account',
32 type='many2one',
33 relation='account.account',
34 string="Stock Valuation Account",
35 view_load=True,
36 help="When real-time inventory valuation is enabled on a product, this account will hold the current value of the products.",),
37 }
38
39 def get_product_accounts(self, cr, uid, product_id, context=None):
40 """ To get the stock input account, stock output account and stock journal related to product.
41 @param product_id: product id
42 @return: dictionary which contains information regarding stock input account, stock output account and stock journal
43 """
44 if context is None:
45 context = {}
46 product_obj = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
47
48 stock_input_acc = product_obj.property_stock_account_input and product_obj.property_stock_account_input.id or False
49 if not stock_input_acc:
50 stock_input_acc = product_obj.categ_id.property_stock_account_input_categ and product_obj.categ_id.property_stock_account_input_categ.id or False
51
52 stock_output_acc = product_obj.property_stock_account_output and product_obj.property_stock_account_output.id or False
53 if not stock_output_acc:
54 stock_output_acc = product_obj.categ_id.property_stock_account_output_categ and product_obj.categ_id.property_stock_account_output_categ.id or False
55
56 journal_id = product_obj.categ_id.property_stock_journal and product_obj.categ_id.property_stock_journal.id or False
57 account_valuation = product_obj.property_stock_valuation_account_id and product_obj.property_stock_valuation_account_id.id or False
58 if not account_valuation:
59 return super(product_product, self).get_product_accounts(cr, uid, product_id, context=context)
60 return {
61 'stock_account_input': stock_input_acc,
62 'stock_account_output': stock_output_acc,
63 'stock_journal': journal_id,
64 'property_stock_valuation_account_id': account_valuation
65 }
66
67
68 def do_change_standard_price(self, cr, uid, ids, datas, context=None):
69 """ Changes the Standard Price of Product and creates an account move accordingly.
70 @param datas : dict. contain default datas like new_price, stock_output_account, stock_input_account, stock_journal
71 @param context: A standard dictionary
72 @return:
73
74 """
75 location_obj = self.pool.get('stock.location')
76 move_obj = self.pool.get('account.move')
77 move_line_obj = self.pool.get('account.move.line')
78 if context is None:
79 context = {}
80
81 new_price = datas.get('new_price', 0.0)
82 stock_output_acc = datas.get('stock_output_account', False)
83 stock_input_acc = datas.get('stock_input_account', False)
84 journal_id = datas.get('stock_journal', False)
85 product_obj=self.browse(cr, uid, ids, context=context)[0]
86 account_valuation = product_obj.property_stock_valuation_account_id
87 if not account_valuation:
88 return super(product_product, self).do_change_standard_price(cr, uid, ids, datas, context=context)
89
90 account_valuation_id = account_valuation and account_valuation.id or False
91 if not account_valuation_id: raise osv.except_osv(_('Error!'), _('Specify valuation Account for Product Category: %s.') % (product_obj.categ_id.name))
92 move_ids = []
93 loc_ids = location_obj.search(cr, uid,[('usage','=','internal')])
94 for rec_id in ids:
95 for location in location_obj.browse(cr, uid, loc_ids, context=context):
96 c = context.copy()
97 c.update({
98 'location': location.id,
99 'compute_child': False
100 })
101
102 product = self.browse(cr, uid, rec_id, context=c)
103 qty = product.qty_available
104 diff = product.standard_price - new_price
105 if not diff: raise osv.except_osv(_('Error!'), _("No difference between standard price and new price!"))
106 if qty:
107 company_id = location.company_id and location.company_id.id or False
108 if not company_id: raise osv.except_osv(_('Error!'), _('Please specify company in Location.'))
109 #
110 # Accounting Entries
111 #
112 if not journal_id:
113 journal_id = product.categ_id.property_stock_journal and product.categ_id.property_stock_journal.id or False
114 if not journal_id:
115 raise osv.except_osv(_('Error!'),
116 _('Please define journal '\
117 'on the product category: "%s" (id: %d).') % \
118 (product.categ_id.name,
119 product.categ_id.id,))
120 move_id = move_obj.create(cr, uid, {
121 'journal_id': journal_id,
122 'company_id': company_id
123 })
124
125 move_ids.append(move_id)
126
127
128 if diff > 0:
129 if not stock_input_acc:
130 stock_input_acc = product.\
131 property_stock_account_input.id
132 if not stock_input_acc:
133 stock_input_acc = product.categ_id.\
134 property_stock_account_input_categ.id
135 if not stock_input_acc:
136 raise osv.except_osv(_('Error!'),
137 _('Please define stock input account ' \
138 'for this product: "%s" (id: %d).') % \
139 (product.name,
140 product.id,))
141 amount_diff = qty * diff
142 move_line_obj.create(cr, uid, {
143 'name': product.name,
144 'account_id': stock_input_acc,
145 'debit': amount_diff,
146 'move_id': move_id,
147 })
148 move_line_obj.create(cr, uid, {
149 'name': product.categ_id.name,
150 'account_id': account_valuation_id,
151 'credit': amount_diff,
152 'move_id': move_id
153 })
154 elif diff < 0:
155 if not stock_output_acc:
156 stock_output_acc = product.\
157 property_stock_account_output.id
158 if not stock_output_acc:
159 stock_output_acc = product.categ_id.\
160 property_stock_account_output_categ.id
161 if not stock_output_acc:
162 raise osv.except_osv(_('Error!'),
163 _('Please define stock output account ' \
164 'for this product: "%s" (id: %d).') % \
165 (product.name,
166 product.id,))
167 amount_diff = qty * -diff
168 move_line_obj.create(cr, uid, {
169 'name': product.name,
170 'account_id': stock_output_acc,
171 'credit': amount_diff,
172 'move_id': move_id
173 })
174 move_line_obj.create(cr, uid, {
175 'name': product.categ_id.name,
176 'account_id': account_valuation_id,
177 'debit': amount_diff,
178 'move_id': move_id
179 })
180
181 self.write(cr, uid, rec_id, {'standard_price': new_price})
182
183 return move_ids
184
185class mrp_production(osv.Model):
186 _inherit = 'mrp.production'
187
188 def get_journal_accounts(self, cr, uid, product, production, context={}):
189
190 if not context:
191 context = {}
192
193 src_acc = False
194 dest_acc = False
195 entrie = False
196
197 if context.get('type', False) == 'consumed':
198 if product.quantity > 0:
199 if production.product_id.property_stock_production.valuation_in_account_id:
200 src_acc = production.product_id.property_stock_production.valuation_in_account_id.id
201 if product.product_id.type == 'service':
202 dest_acc = product.property_stock_valuation_account_id and\
203 product.property_stock_valuation_account_id.id or False
204 if not dest_acc:
205 dest_acc = product.product_id.categ_id.property_stock_valuation_account_id and\
206 product.product_id.categ_id.property_stock_valuation_account_id.id or False
207 entrie = True
208 elif production.product_id.property_stock_production.variation_in_account_id:
209 dest_acc = production.product_id.property_stock_production.variation_in_account_id.id
210 reference_amount = product.cost_variation
211
212 if product.quantity < 0:
213 if product.product_id.type == 'service':
214 src_acc = product.property_stock_valuation_account_id and\
215 product.property_stock_valuation_account_id.id or False
216 if not src_acc:
217 src_acc = product.product_id.categ_id.property_stock_valuation_account_id and\
218 product.product_id.categ_id.property_stock_valuation_account_id.id or False
219 entrie = True
220 elif production.product_id.property_stock_production.variation_in_account_id:
221 src_acc = production.product_id.property_stock_production.variation_in_account_id.id
222 if production.product_id.property_stock_production.valuation_in_account_id:
223 dest_acc = production.product_id.property_stock_production.valuation_in_account_id.id
224 reference_amount = product.cost_variation*-1
225
226 if entrie:
227 return super(mrp_production, self).get_journal_accounts(cr, uid, product, production, context=context)
228
229 if context.get('type', False) == 'produced':
230 if product.quantity > 0:
231 if production.product_id.property_stock_production.valuation_out_account_id:
232 src_acc = production.product_id.property_stock_production.variation_out_account_id.id
233 if production.product_id.property_stock_production.variation_out_account_id:
234 dest_acc = production.product_id.property_stock_production.valuation_out_account_id.id
235 reference_amount = product.cost_variation
236 if product.quantity < 0:
237 if production.product_id.property_stock_production.variation_out_account_id:
238 src_acc = production.product_id.property_stock_production.valuation_out_account_id.id
239 if production.product_id.property_stock_production.valuation_out_account_id:
240 dest_acc = production.product_id.property_stock_production.variation_out_account_id.id
241 reference_amount = product.cost_variation*-1
242
243 journal_id = product.product_id.categ_id.property_stock_journal.id
244 if not src_acc or not dest_acc:
245 raise osv.except_osv(_('Error!'),
246 _('There is no account defined for this location: "%s" ') %
247 (production.product_id.property_stock_production.name,))
248
249 if not journal_id:
250 raise osv.except_osv(_('Error!'),
251 _('There is no journal defined on the product category:\
252 "%s" (id: %d)') %
253 (product.product_id.categ_id.name,
254 product.product_id.categ_id.id,))
255
256 return journal_id, src_acc, dest_acc, reference_amount
0257
=== added directory 'stock_valuation_account_product/view'
=== added file 'stock_valuation_account_product/view/product_product_stock_valuation_account.xml'
--- stock_valuation_account_product/view/product_product_stock_valuation_account.xml 1970-01-01 00:00:00 +0000
+++ stock_valuation_account_product/view/product_product_stock_valuation_account.xml 2013-09-12 21:23:37 +0000
@@ -0,0 +1,20 @@
1<?xml version='1.0' encoding='UTF-8'?>
2<openerp>
3 <data>
4 <record id="view_product_stock_valuation_account_inherit" model="ir.ui.view">
5 <field name="name">view.product.stock.valuation.account.inherit</field>
6 <field name="model">product.product</field>
7 <field name="inherit_id" ref="product.product_normal_form_view"/>
8 <field name="priority">30</field>
9 <field name="arch" type="xml">
10 <xpath expr="//field[@name='property_stock_account_output']" position="after">
11 <field name="property_stock_valuation_account_id" attrs="{'invisible':[('valuation', '!=', 'real_time')]}"
12 domain="[('type','&lt;&gt;','view'),('type','&lt;&gt;','consolidation')]"/>
13 </xpath>
14 </field>
15 </record>
16 </data>
17</openerp>
18
19
20