Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from Eficent/8.0-ms-product_supplierinfo_for_…
…customer [8.0][IMP] product_supplierinfo_for_customer add hook
- Loading branch information
Showing
4 changed files
with
86 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,5 @@ | |
"demo/product_demo.xml", | ||
], | ||
"installable": True, | ||
"post_init_hook": "post_init_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2017 Eficent Business and IT Consulting Services S.L. | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) | ||
from openerp.api import Environment | ||
from openerp import SUPERUSER_ID | ||
|
||
|
||
def import_customer_code(env): | ||
env.cr.execute("""SELECT column_name | ||
FROM information_schema.columns | ||
WHERE table_name='product_customer_code'""") | ||
if env.cr.fetchone(): | ||
env.cr.execute(""" | ||
select product_id, | ||
product_code, partner_id, company_id, product_name | ||
from product_customer_code | ||
""") | ||
for product_id, product_code, partner_id, company_id, product_name in \ | ||
env.cr.fetchall(): | ||
pt_id = env['product.product'].browse( | ||
product_id).product_tmpl_id.id | ||
vals = {'name': partner_id, | ||
'product_tmpl_id': pt_id, | ||
'product_code': product_code, | ||
'type': 'customer', | ||
'pricelist_ids': [( | ||
0, 0, {'price': 0.0, 'min_quantity': 0.0})], | ||
} | ||
env['product.supplierinfo'].create(vals) | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
env = Environment(cr, SUPERUSER_ID, {}) | ||
import_customer_code(env) |