Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to detect if sale order is created from admin or from website?

By
Pascal Tremblay
on 10/30/15, 6:02 PM 422 views

Hello guys,

In the create method of the sale.order class, in the python code, how would you detect if the sale order is created from the backend or the frontend?

Would you use the url?

In my company, sale orders created from the frontend must take a sequence and sale orders created from the backend must take an other sequence. 

0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 10/30/15, 9:18 PM

Here is my override of the create method :


def create(self, cr, uid, vals, context=None): 

    if context is None:

        context = {} 

    urlll = str(request.httprequest.url)

    if 'sale.order' not in urlll:

        if vals.get('name', '/') == '/':

            vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'sale.order.web', context=context) or '/'

        if vals.get('partner_id') and any(f not in vals for f in ['partner_invoice_id', 'partner_shipping_id', 'pricelist_id', 'fiscal_position']):

            defaults = self.onchange_partner_id(cr, uid, [], vals['partner_id'], context=context)['value']

            if not vals.get('fiscal_position') and vals.get('partner_shipping_id'):

                delivery_onchange = self.onchange_delivery_id(cr, uid, [], vals.get('company_id'), None, vals['partner_id'], vals.get('partner_shipping_id'), context=context)

                defaults.update(delivery_onchange['value'])

           vals = dict(defaults, **vals)

    ctx = dict(context or {}, mail_create_nolog=True)

    new_id = super(sale_order, self).create(cr, uid, vals, context=ctx)

    self.message_post(cr, uid, [new_id], body=_("Quotation created"), context=ctx)


    return new_id

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/30/15, 6:02 PM
Seen: 422 times
Last updated: 10/30/15, 9:19 PM