This question has been flagged

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.

Avatar
Discard
Best Answer

Hi,
In the case of odoo9 the public user will be of user_id 3 and treated as according to his rights. The case is now odoo can take compnay_id of the public user wherein demo created. But you can manage portal users and according to the creation of portal users company_id will set, still, the case is no support fro multi website and the company_id should be 1 in default. So better would be make filters in other ways.

Avatar
Discard
Author Best Answer

I asked, i answered...

controllers/main.py
def checkout_form_save(self, checkout):
        cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
        order = request.website.sale_get_order(force_create=1, context=context)

        orm_partner = registry.get('res.partner')
        orm_user = registry.get('res.users')
        order_obj = request.registry.get('sale.order')

        partner_lang = request.lang if request.lang in [lang.code for lang in request.website.language_ids] else None
        billing_info = {'customer': True}
        #Set company_id
        billing_info = {'company_id': order.company_id.id }
...

Avatar
Discard