avanzosc team mailing list archive
-
avanzosc team
-
Mailing list archive
-
Message #00451
[Merge] lp:~dani-ds/avanzosc/dos_product_additional_info into lp:~avanzosc-security-team/avanzosc/72horas
Daniel Campos (Avanzosc) has proposed merging lp:~dani-ds/avanzosc/dos_product_additional_info into lp:~avanzosc-security-team/avanzosc/72horas.
Requested reviews:
Avanzosc_security (avanzosc-security-team)
For more details, see:
https://code.launchpad.net/~dani-ds/avanzosc/dos_product_additional_info/+merge/223034
Refactorizado módulo dos_product_additional_info
--
https://code.launchpad.net/~dani-ds/avanzosc/dos_product_additional_info/+merge/223034
Your team Avanzosc_security is requested to review the proposed merge of lp:~dani-ds/avanzosc/dos_product_additional_info into lp:~avanzosc-security-team/avanzosc/72horas.
=== modified file 'dos_account_fix_compute/__openerp__.py'
--- dos_account_fix_compute/__openerp__.py 2014-06-11 10:23:47 +0000
+++ dos_account_fix_compute/__openerp__.py 2014-06-13 08:12:07 +0000
@@ -21,17 +21,14 @@
{
- "name" : "DOS Account Fix Compute",
- "version" : "1.0",
- "author" : "DOS",
- "category" : "Account",
- "website" : "www.dos-sl.es",
- "description": "This module fix compute calculations of accounts.",
- "depends" : ["account"],
- "init_xml" : [],
- "update_xml" : [],
- "active": False,
- "installable": True
+ 'name': 'DOS Account Fix Compute',
+ 'version': '1.0',
+ 'author': 'DOS',
+ 'category': 'Account',
+ 'website': 'www.dos-sl.es',
+ 'description': 'This module fix compute calculations of accounts.',
+ 'depends': ['account'],
+ 'data': [],
+ 'active': False,
+ 'installable': True
}
-
-
=== added directory 'dos_account_fix_compute/models'
=== renamed file 'dos_account_fix_compute/account.py' => 'dos_account_fix_compute/models/account.py'
--- dos_account_fix_compute/account.py 2014-06-11 10:23:47 +0000
+++ dos_account_fix_compute/models/account.py 2014-06-13 08:12:07 +0000
@@ -19,152 +19,146 @@
#
##############################################################################
-import netsvc
-from osv import fields, osv
-import decimal_precision as dp
-from tools.translate import _
-
-class account_account(osv.osv):
-
- _inherit ="account.account"
-
- def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
- query='', query_params=()):
- """ compute the balance, debit and/or credit for the provided
- account ids
- Arguments:
- `ids`: account ids
- `field_names`: the fields to compute (a list of any of
- 'balance', 'debit' and 'credit')
- `arg`: unused fields.function stuff
- `query`: additional query filter (as a string)
- `query_params`: parameters for the provided query string
- (__compute will handle their escaping) as a
- tuple
- """
-
- mapping = {
- 'balance': "COALESCE(SUM(balance),0) as balance",
- 'debit': "COALESCE(SUM(debit), 0) as debit",
- 'credit': "COALESCE(SUM(credit), 0) as credit"
- }
- #get all the necessary accounts
- children_and_consolidated = ids
-
- #compute for each account the balance/debit/credit from the move lines
- accounts = {}
- if children_and_consolidated:
- aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
-
- wheres = [""]
- if query.strip():
- wheres.append(query.strip())
- if aml_query.strip():
- wheres.append(aml_query.strip())
- filters = " AND ".join(wheres)
-
- self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
- 'Filters: %s'%filters)
-
- # Compute credit, debit, balane
-
-
- request = ("SELECT id, " \
- " MIN(code) As code, " \
- +\
- ', '.join(map(mapping.__getitem__, field_names)) +
- " FROM " \
- " ( " \
- " SELECT aa_tree_1.id As id, " \
- " aa_tree_1.code AS code, " \
- " aa_tree_1.currency_id AS to_currency, " \
- " c.rate AS to_rate, " \
- " aa_tree_2.code AS code2, " \
- " aa_tree_2.currency_id AS from_currency, " \
- " c2.rate AS from_rate, " \
- " l.period_id, " \
- " l.date As date, " \
- " ROUND(l.debit * (COALESCE(c.rate,1) / COALESCE(c2.rate,1)), 2) AS debit, " \
- " ROUND(l.credit * (COALESCE(c.rate,1) / COALESCE(c2.rate,1)), 2) AS credit, " \
- " ROUND((l.debit * (COALESCE(c.rate,1) / COALESCE(c2.rate,1))) - (l.credit * (COALESCE(c.rate,1) / COALESCE(c2.rate,1))), 2) AS balance " \
- " FROM account_account aa_tree_1 " \
- " INNER JOIN account_account aa_tree_2 " \
- " ON aa_tree_2.parent_left " \
- " BETWEEN aa_tree_1.parent_left AND aa_tree_1.parent_right " \
- " AND aa_tree_1.company_id=aa_tree_2.company_id " \
- " LEFT JOIN ( " \
- " SELECT c.id, r.rate " \
- " FROM res_currency c " \
- " INNER JOIN res_currency_rate r ON c.id=r.currency_id " \
- " GROUP BY c.id, r.name, r.rate " \
- " HAVING r.name = MAX(r.name) " \
- " LIMIT 1 " \
- " ) c ON c.id = aa_tree_1.currency_id " \
- " LEFT JOIN ( " \
- " SELECT c.id, r.rate " \
- " FROM res_currency c " \
- " INNER JOIN res_currency_rate r ON c.id=r.currency_id " \
- " GROUP BY c.id, r.name, r.rate " \
- " HAVING r.name = MAX(r.name) " \
- " LIMIT 1 " \
- " ) c2 ON c2.id = aa_tree_2.currency_id " \
- " INNER JOIN account_move_line l" \
- " ON l.account_id = aa_tree_2.id " \
- " WHERE aa_tree_1.id IN %s " \
- + filters +
- " ) a " \
- " GROUP BY a.id")
-
- """
- request = ("SELECT aa_tree_1.id, " \
- "MIN(aa_tree_1.code) AS code, " \
- +\
- ', '.join(map(mapping.__getitem__, field_names)) +
- " FROM account_account aa_tree_1" \
- " INNER JOIN account_account aa_tree_2" \
- " ON aa_tree_2.parent_left" \
- " BETWEEN aa_tree_1.parent_left AND aa_tree_1.parent_right" \
- " AND aa_tree_1.company_id=aa_tree_2.company_id" \
- " INNER JOIN account_move_line l" \
- " ON l.account_id = aa_tree_2.id" \
- " WHERE aa_tree_1.id IN %s " \
- + filters +
- " GROUP BY aa_tree_1.id")
- """
-
- params = (tuple(children_and_consolidated),) + query_params
- cr.execute(request, params)
-
- self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
- 'Status: %s'%cr.statusmessage)
-
- for res in cr.dictfetchall():
- accounts[res['id']] = res
-
- # consolidate accounts with direct children
- children_and_consolidated.reverse()
- brs = list(self.browse(cr, uid, children_and_consolidated, context=context))
- sums = {}
-
- while brs:
- current = brs[0]
-
- brs.pop(0)
- for fn in field_names:
- sums.setdefault(current.id, {})[fn] = accounts.get(current.id, {}).get(fn, 0.0)
-
- res = {}
- null_result = dict((fn, 0.0) for fn in field_names)
- for acc_id in ids:
- res[acc_id] = sums.get(acc_id, null_result)
-
- return res
-
-
- _columns = {
- 'balance': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Balance', multi='balance'),
- 'credit': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Credit', multi='balance'),
- 'debit': fields.function(__compute, digits_compute=dp.get_precision('Account'), method=True, string='Debit', multi='balance'),
- }
-
-account_account()
+from openerp.osv import fields, orm
+import openerp.addons.decimal_precision as dp
+from openerp.tools.translate import _
+import logging
+
+logger = logging.getLogger('dos_account_fix_compute')
+
+
+class AccountAccount(orm.Model):
+ _inherit = "account.account"
+
+ def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
+ query='', query_params=()):
+ """Compute the balance, debit and/or credit for the provided account
+ ids.
+ :param ids: account ids
+ :param field_names: the fields to compute (a list of any of \
+ 'balance', 'debit' and 'credit')
+ :param arg: unused fields.function stuff
+ :param query: additional query filter (as a string)
+ :param query_params: parameters for the provided query string \
+ (__compute will handle their escaping) as a tuple
+ """
+ mapping = {'balance': "COALESCE(SUM(balance),0) as balance",
+ 'debit': "COALESCE(SUM(debit), 0) as debit",
+ 'credit': "COALESCE(SUM(credit), 0) as credit"}
+ # get all the necessary accounts
+ children_and_consolidated = ids
+ accounts = {}
+ # compute for each account the balance/debit/credit from the move lines
+ if children_and_consolidated:
+ acc_mline_obj = self.pool['account.move.line']
+ aml_query = acc_mline_obj ._query_get(cr, uid, context=context)
+ wheres = [""]
+ if query.strip():
+ wheres.append(query.strip())
+ if aml_query.strip():
+ wheres.append(aml_query.strip())
+ filters = " AND ".join(wheres)
+ logger.debug('Filters: %s' % filters)
+ # Compute credit, debit, balane
+ request = ("SELECT id, "
+ " MIN(code) As code, " +
+ ', '.join(map(mapping.__getitem__, field_names)) +
+ " FROM "
+ " ( "
+ " SELECT aa_tree_1.id As id, "
+ " aa_tree_1.code AS code, "
+ " aa_tree_1.currency_id AS to_currency, "
+ " c.rate AS to_rate, "
+ " aa_tree_2.code AS code2, "
+ " aa_tree_2.currency_id AS from_currency, "
+ " c2.rate AS from_rate, "
+ " l.period_id, "
+ " l.date As date, "
+ " ROUND(l.debit * (COALESCE(c.rate,1) / "
+ "COALESCE(c2.rate,1)), 2) AS debit, "
+ " ROUND(l.credit * (COALESCE(c.rate,1) / "
+ "COALESCE(c2.rate,1)), 2) AS credit, "
+ " ROUND((l.debit * (COALESCE(c.rate,1) / "
+ "COALESCE(c2.rate,1))) - (l.credit * "
+ "(COALESCE(c.rate,1) / "
+ "COALESCE(c2.rate,1))), 2) AS balance "
+ " FROM account_account aa_tree_1 "
+ " INNER JOIN account_account aa_tree_2 "
+ " ON aa_tree_2.parent_left "
+ " BETWEEN aa_tree_1.parent_left AND"
+ " aa_tree_1.parent_right "
+ " AND aa_tree_1.company_id = aa_tree_2.company_id"
+ " LEFT JOIN ( "
+ " SELECT c.id, r.rate "
+ " FROM res_currency c "
+ " INNER JOIN res_currency_rate r "
+ " ON c.id=r.currency_id "
+ " GROUP BY c.id, r.name, r.rate "
+ " HAVING r.name = MAX(r.name) "
+ " LIMIT 1 "
+ " ) c ON c.id = aa_tree_1.currency_id "
+ " LEFT JOIN ( "
+ " SELECT c.id, r.rate "
+ " FROM res_currency c "
+ " INNER JOIN res_currency_rate r ON"
+ " c.id=r.currency_id "
+ " GROUP BY c.id, r.name, r.rate "
+ " HAVING r.name = MAX(r.name) "
+ " LIMIT 1 "
+ " ) c2 ON c2.id = aa_tree_2.currency_id "
+ " INNER JOIN account_move_line l"
+ " ON l.account_id = aa_tree_2.id "
+ " WHERE aa_tree_1.id IN %s "
+ + filters +
+ " ) a "
+ " GROUP BY a.id")
+ """
+ request = ("SELECT aa_tree_1.id, " \
+ "MIN(aa_tree_1.code) AS code, " \
+ +\
+ ', '.join(map(mapping.__getitem__, field_names)) +
+ " FROM account_account aa_tree_1" \
+ " INNER JOIN account_account aa_tree_2" \
+ " ON aa_tree_2.parent_left" \
+ " BETWEEN aa_tree_1.parent_left AND "
+ " aa_tree_1.parent_right" \
+ " AND aa_tree_1.company_id=aa_tree_2.company_id" \
+ " INNER JOIN account_move_line l" \
+ " ON l.account_id = aa_tree_2.id" \
+ " WHERE aa_tree_1.id IN %s " \
+ + filters +
+ " GROUP BY aa_tree_1.id")
+ """
+ params = (tuple(children_and_consolidated),) + query_params
+ cr.execute(request, params)
+ logger.debug('Status: %s' % cr.statusmessage)
+ for res in cr.dictfetchall():
+ accounts[res['id']] = res
+ # consolidate accounts with direct children
+ children_and_consolidated.reverse()
+ brs = list(self.browse(cr, uid, children_and_consolidated,
+ context=context))
+ sums = {}
+ while brs:
+ current = brs[0]
+ brs.pop(0)
+ for fn in field_names:
+ result_1 = accounts.get(current.id, {}).get(fn, 0.0)
+ sums.setdefault(current.id, {})[fn] = result_1
+ res = {}
+ null_result = dict((fn, 0.0) for fn in field_names)
+ for acc_id in ids:
+ res[acc_id] = sums.get(acc_id, null_result)
+ return res
+
+ _columns = {
+ 'balance': fields.function(__compute, method=True,
+ digits_compute=dp.get_precision('Account'),
+ string='Balance', multi='balance'),
+ 'credit': fields.function(__compute, method=True,
+ digits_compute=dp.get_precision('Account'),
+ string='Credit', multi='balance'),
+ 'debit': fields.function(__compute, method=True,
+ digits_compute=dp.get_precision('Account'),
+ string='Debit', multi='balance'),
+ }
=== modified file 'dos_product_additional_info/__openerp__.py'
--- dos_product_additional_info/__openerp__.py 2014-06-11 10:23:47 +0000
+++ dos_product_additional_info/__openerp__.py 2014-06-13 08:12:07 +0000
@@ -21,17 +21,14 @@
{
- "name" : "DOS Product Additional Info",
- "version" : "1.0",
- "author" : "DOS",
- "category" : "Product",
- "website" : "www.dos-sl.es",
+ "name": "DOS Product Additional Info",
+ "version": "1.0",
+ "author": "DOS",
+ "category": "Product",
+ "website": "www.dos-sl.es",
"description": "This module adds extra information to products",
- "depends" : ['product'],
- "init_xml" : [],
- "update_xml" : ['product_view.xml'],
+ "depends": ['product'],
+ "data": ['view/product_view.xml'],
"active": False,
"installable": True
}
-
-
=== added directory 'dos_product_additional_info/models'
=== added file 'dos_product_additional_info/models/product.py'
--- dos_product_additional_info/models/product.py 1970-01-01 00:00:00 +0000
+++ dos_product_additional_info/models/product.py 2014-06-13 08:12:07 +0000
@@ -0,0 +1,122 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.osv import orm, fields
+from openerp.tools.translate import _
+import openerp.addons.re
+
+
+class ProductProduct(orm.Model):
+ _inherit = 'product.product'
+
+ _columns = {
+ 'commissionable': fields.boolean('Commissionable',
+ help="If the commissionable field is "
+ "set to True, it will allow you to "
+ "pay commission on the sale of the "
+ "product."),
+ }
+
+ def pack_components(self, product):
+ product_sim_id = product_link_id = None
+ if self._is_pack(product.categ_id):
+ for mrp_bom in product.bom_ids:
+ for line in mrp_bom.bom_lines:
+ categ_id = line.product_id.categ_id
+ if line.product_id and self._is_sim(categ_id):
+ product_sim_id = line.product_id.id
+ elif line.product_id and self._is_link(categ_id):
+ product_link_id = line.product_id.id
+ break
+ return product_sim_id, product_link_id
+
+ def _is_sim(self, category):
+ if not category:
+ return False
+ if category.name == 'Tarjetas SIM':
+ return True
+ else:
+ return self._is_sim(category.parent_id)
+
+ def _is_link(self, category):
+ if not category:
+ return False
+ if category.name == 'Enlaces':
+ return True
+ else:
+ return self._is_link(category.parent_id)
+
+ def _is_pack(self, category):
+ if not category:
+ return False
+ if category.name == 'Packs':
+ return True
+ else:
+ return self._is_pack(category.parent_id)
+
+ def _is_shipping_cost(self, category):
+ if not category:
+ return False
+ if category.name == 'Gastos de Envío' or category.id == 4:
+ return True
+ else:
+ return self._is_shipping_cost(category.parent_id)
+
+
+class ProductTemplate(orm.Model):
+ _inherit = 'product.template'
+
+ _columns = {
+ 'property_stock_finished_product': fields.property(
+ 'stock.location',
+ type='many2one',
+ relation='stock.location',
+ string="Finished Product Location",
+ method=True,
+ view_load=True,
+ domain=[('usage', 'like', 'internal')],
+ help="For the current product, this stock location will be used, "
+ "instead of the default one, as the location of origin of products"
+ " whose manufacture has been completed"),
+ 'property_stock_consumer_product': fields.property(
+ 'stock.location',
+ type='many2one',
+ relation='stock.location',
+ string="Consumer Product Location",
+ method=True,
+ view_load=True,
+ domain=[('usage', 'like', 'internal')],
+ help="For the current product, this stock location will be used, "
+ "instead of the default one, as the source location for "
+ "consumption of the product"),
+ 'unitary_prod_order': fields.boolean('Unitary production order',
+ help="If the unitary production "
+ "order field is set to True, it "
+ "will generate production orders "
+ "from unit to unit."),
+ 'discount': fields.float('Discount', digits=(2, 2),
+ help="Discount applies if the product is "
+ "rented."),
+ }
+ _defaults = {
+ 'unitary_prod_order': False,
+ 'discount': 0,
+ }
=== removed file 'dos_product_additional_info/product.py'
--- dos_product_additional_info/product.py 2014-06-11 10:23:47 +0000
+++ dos_product_additional_info/product.py 1970-01-01 00:00:00 +0000
@@ -1,130 +0,0 @@
-# -*- coding: utf-8 -*-
-##############################################################################
-#
-# OpenERP, Open Source Management Solution
-# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, either version 3 of the
-# License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-#
-##############################################################################
-
-from osv import osv, fields
-import re
-from tools.translate import _
-
-class product_product(osv.osv):
-
- _name = 'product.product'
- _inherit = 'product.product'
-
- _columns = {
- 'commissionable': fields.boolean('Commissionable', help="If the commissionable field is set to True, it will allow you to pay commission on the sale of the product."),
- }
-
-
- def pack_components(self, product):
-
- product_sim_id = product_link_id = None
-
- if self._is_pack(product.categ_id):
- for mrp_bom in product.bom_ids:
- for line in mrp_bom.bom_lines:
- if line.product_id and self._is_sim(line.product_id.categ_id):
- product_sim_id = line.product_id.id
- elif line.product_id and self._is_link(line.product_id.categ_id):
- product_link_id = line.product_id.id
- break
-
- return product_sim_id, product_link_id
-
- def _is_sim(self, category):
- if not category:
- return False
-
- if category.name == 'Tarjetas SIM':
- return True
- else:
- return self._is_sim(category.parent_id)
-
-
- def _is_link(self, category):
- if not category:
- return False
-
- if category.name == 'Enlaces':
- return True
- else:
- return self._is_link(category.parent_id)
-
-
- def _is_pack(self, category):
- if not category:
- return False
-
- if category.name == 'Packs':
- return True
- else:
- return self._is_pack(category.parent_id)
-
- def _is_shipping_cost(self, category):
- if not category:
- return False
-
- if category.name == 'Gastos de Envío' or category.id == 4:
- return True
- else:
- return self._is_shipping_cost(category.parent_id)
-
-product_product()
-
-class product_template(osv.osv):
-
- _name = 'product.template'
- _inherit = 'product.template'
- _columns = {
- 'property_stock_finished_product': fields.property(
- 'stock.location',
- type='many2one',
- relation='stock.location',
- string="Finished Product Location",
- method=True,
- view_load=True,
- domain=[('usage','like','internal')],
- help="For the current product, this stock location will be used, instead of the default one, as the location of origin of products whose manufacture has been completed"),
-
- 'property_stock_consumer_product': fields.property(
- 'stock.location',
- type='many2one',
- relation='stock.location',
- string="Consumer Product Location",
- method=True,
- view_load=True,
- domain=[('usage','like','internal')],
- help="For the current product, this stock location will be used, instead of the default one, as the source location for consumption of the product"),
-
- 'unitary_prod_order': fields.boolean('Unitary production order', help="If the unitary production order field is set to True, it will generate production orders from unit to unit."),
- 'discount': fields.float('Discount', digits=(2,2), help="Discount applies if the product is rented."),
- }
-
- _defaults = {
- 'unitary_prod_order': False,
- 'discount': 0,
- }
-
-product_template()
-
-
-
-
-
=== added directory 'dos_product_additional_info/views'
=== renamed file 'dos_product_additional_info/product_view.xml' => 'dos_product_additional_info/views/product_view.xml'
Follow ups