Created
December 24, 2018 06:33
-
-
Save phucngta/ee38d05379417371433c2b3b571074c5 to your computer and use it in GitHub Desktop.
installer
This file contains hidden or 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
| import logging | |
| from odoo import api, fields, models | |
| _logger = logging.getLogger(__name__) | |
| class EcoBambou(models.TransientModel): | |
| _name = 'eco_bambou_all.installer' | |
| _inherit = 'installer.helper' | |
| _description = 'eco_bambou_all installer' | |
| @api.model | |
| def start(self): | |
| self.run_only_once('eco_bambou_all.installer', [ | |
| 'config_pos', | |
| 'create_role_functional_admin', | |
| 'update_company_info', | |
| 'update_latest_date_sale', | |
| 'set_config', | |
| ]) | |
| self.set_report_url() | |
| return True | |
| @api.model | |
| def set_config(self): | |
| config_page = 'res.config.settings' | |
| vals = { | |
| 'group_product_variant': 0, | |
| 'group_stock_multi_locations': 1, | |
| 'group_stock_multi_warehouses': 1, | |
| 'group_multi_currency': 1, | |
| } | |
| logging.info("Executing ") | |
| config = self.env[config_page].create(vals) | |
| logging.info("Executing config %s with vals %s " % ( | |
| config_page, str(vals))) | |
| config.execute() | |
| logging.info("Config %s done!" % config_page) | |
| @api.model | |
| def create_role_functional_admin(self): | |
| self.env['res.users.role'].save_role_functional_admin( | |
| technical_settings=( | |
| "Manage Multiple Stock Locations", | |
| "Manage Multiple Warehouses", | |
| "Manage Pricelist Items", | |
| 'Show Full Accounting Features', | |
| "Tax display B2C", | |
| 'Discount on lines', | |
| 'Sales Pricelists', | |
| "Tax display B2B", | |
| 'Contact Creation', | |
| ) | |
| ) | |
| return True | |
| @api.model | |
| def update_company_info(self): | |
| state = self.env['res.country.state'].create({ | |
| 'code': 'KH', | |
| 'name': 'Khanh Hoa', | |
| 'country_id': self.env.ref('base.vn').id, | |
| }) | |
| self.env.ref('base.main_company').write( | |
| { | |
| 'name': 'BAMBOU COMPANY', | |
| 'vat': '4200520116', | |
| 'street': '15 Biet Thu Street', | |
| 'street2': 'Nha Trang City', | |
| 'state_id': state.id, | |
| 'country_id': self.env.ref('base.vn').id, | |
| } | |
| ) | |
| @api.model | |
| def config_pos(self): | |
| main_pos = self.env.ref('point_of_sale.pos_config_main') | |
| main_pos.active = False | |
| cash_pos_journal = self.env.ref('eco_bambou_all.cash_pos_sale_journal') | |
| credit_card_journal = self.env.ref( | |
| 'eco_bambou_all.credit_card_pos_sale_journal') | |
| currencies = self.env['res.currency'].search([('active', '=', True)]) | |
| pos_configs = self.env['pos.config'].search([]) | |
| pos_configs.update({ | |
| 'journal_ids': [ | |
| (6, 0, [cash_pos_journal.id, credit_card_journal.id])], | |
| 'enable_multi_currency': True, | |
| 'pos_currencies': [(6, 0, currencies.ids)], | |
| }) | |
| @api.model | |
| def update_latest_date_sale(self): | |
| pos_orders = self.env['pos.order'].search([]) | |
| for order in pos_orders: | |
| logging.info("Loading order: %s", order.name) | |
| date_order = fields.Date.from_string(order.date_order) | |
| products = order.lines.mapped('product_id').filtered( | |
| lambda p: | |
| not p.date_latest_sale or | |
| p.date_latest_sale and | |
| fields.Date.from_string(p.date_latest_sale) < date_order) | |
| products.write({'date_latest_sale': order.date_order}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment