Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
5974 Lượt xem

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>



Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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




Ảnh đại diện
Huỷ bỏ
Tác giả

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

Câu trả lời hay nhất

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 :)


Ảnh đại diện
Huỷ bỏ
Tác giả

Very thankful for your answer. YourCompany3SequenceID = seq_sale_order

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

Tác giả

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

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
1922
3
thg 7 25
2344
1
thg 7 25
1597
0
thg 4 25
2627
3
thg 11 24
361