Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
5944 Tampilan

I need to configure the sequence number for my sales quotation. And also I have three companies. I want 

Company1 - AAN01

Company2 - ABM01

Company3 - AZX01

What is the python code for the above requirement?

   @api.model
    def create(self,vals):
            if vals.get('sequence_name', _('New')) == _('New'):
                vals['sequence_name'] = self.env['ir.sequence'].next_by_code('sale.order') or _('New')
            res = super(sale_order, self).create(vals)
            return res


<record id="seq_sale_order" model="ir.sequence">
<field name="name">Sales Order</field>
<field name="code">sale.orders</field>
<field name="prefix">AAN</field>
<field name="padding">3</field>
<field name="company_id" eval="False"/>
</record>



Avatar
Buang
Jawaban Terbai

Hi Remya,

You can just go to: Settings / Technical / Sequences & Identifiers / Sequences / sale.order , and you can create separate sequences for each company (duplicate existing sequence and create one for each company).

See also the answer from:  https://www.odoo.com/forum/help-1/question/configuration-on-odoo-v-13-multi-company-setup-158830#answer-158840

BR

Ricardo




Avatar
Buang
Penulis

That's ok. But I need to implement it through my customized code. Plz guide me to correct the below code

Jawaban Terbai

Hi bro,

To do that you need first to create 3 sequences and define their names and prefix.

Then add this code in your class : 

@api.model
def create(self,vals):
	if self.company_id and vals.get('name', '/') == '/':
		if self.company_id.name =="YourFirstCompanyName":#Company1 
			seq_id = self.pool.get('ir.model.data').get_object_reference(self._cr,self._uid,'sale_order', 'YourCompany1SequenceID')[1]
			self.name = self.pool.get('ir.sequence').get_id(self._cr,self._uid , seq_id, 'id',self._context)

if self.company_id.name =="YourSecondCompanyName":#Company2 seq_id = self.pool.get('ir.model.data').get_object_reference(self._cr,self._uid,'sale_order', 'YourCompany2SequenceID')[1] self.name = self.pool.get('ir.sequence').get_id(self._cr,self._uid , seq_id, 'id',self._context)
if self.company_id.name =="YourThirdCompanyName":#Company3 seq_id = self.pool.get('ir.model.data').get_object_reference(self._cr,self._uid,'sale_order', 'YourCompany3SequenceID')[1] self.name = self.pool.get('ir.sequence').get_id(self._cr,self._uid , seq_id, 'id',self._context) return super(sale_order, self).create(vals)
YourCompany3SequenceID = xml ID of the  sequence for the third company. 

Dont forget to vote positif :)


Avatar
Buang
Penulis

Very thankful for your answer. YourCompany3SequenceID = seq_sale_order

{. <record id="seq_sale_order" model="ir.sequence">}. Right???

Penulis

Yet I didn't get any solution

brther you have tocreate 2 more other sequences , the standard one is what you mentionned, you can use it as sequence for the first company , but you need to create 2 more sequences one for the second company and one for the third.

and it's a tested solution :) it works i promise

Penulis

Hi, I had created 3 sequences for my three different company and mentioned as the above code. But it is not creating a sequence code.

But I will try to solve the issue in my code. Thanks for your reply

Post Terkait Replies Tampilan Aktivitas
2
Jul 25
1911
3
Jul 25
2325
1
Jul 25
1588
0
Apr 25
2619
3
Nov 24
361