I use odoo 8.0 in multicompany mode.
I need to configure the basket: set depending on the selected product company_id and warehouse_id in sales.order. Additionally, I need to install the company_id a new customer.
With values in sales.order understood, I establish so:
models:
# -*- coding: utf-8 -*- from openerp.osv import orm class website(orm.Model): _inherit = 'website' def sale_get_order( self, cr, uid, ids, force_create=False, code=None, update_pricelist=None, context=None ): order = super(website, self).sale_get_order( cr, uid, ids, force_create=force_create, code=code, update_pricelist=update_pricelist, context=context) if order: company = order.get_products_company() if company: order.write({'company_id': company.id}) order.write({'user_id': False}) warehouse = order.get_products_warehouse(cr, context) if warehouse: order.write({'warehouse_id': warehouse}) order.write({'user_id': False}) return order
and
# -*- coding: utf-8 -*-
from openerp import models, SUPERUSER_ID, api
from openerp.osv import fields, osv
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
def get_products_company(self):
"""
Check products companies. If all products have the same company
(or empty), return it
If get_products_company doesn't find a unique company,
the default one id used
(returned by '_get_default_company' of 'sale.order')
"""
companies = {}
company = False
for order in self:
for line in order.order_line:
if line.product_id and line.product_id.company_id:
companies[line.product_id.company_id] = True
if len(companies) == 1:
company = companies.keys()[0]
return company
@api.multi
def get_products_warehouse(self, cr, context):
warehouse_ids = False
for order in self:
for line in order.order_line:
if line.product_id and line.product_id.company_id:
warehouse_ids = self.pool.get('stock.warehouse').search(cr, SUPERUSER_ID, [('company_id', '=', line.product_id.company_id.id)], context=context)
if not warehouse_ids:
return False
return warehouse_ids[0]
How do I set the company_id value of a new customer? Now it is created with the value public_user.company_id.