Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
11055 Visualizzazioni

In the view of the creation of a sale order, i put a number of section for each sale order line (a section allows me to decompose the sale order into multiple parts). When i create the sale order, i want the sale order section to be created too, with the same number i have put in the view. I've heard about overwriting create/write methods but i don't know how to do. Thanks, here is a part of my code :

class sale_order_line(osv.osv):

_name = 'sale.order.line'
_inherit = 'sale.order.line'

_columns = {
            'section_id': fields.many2one('sale.order.section', 'n° section', required=False, ondelete='cascade', select=True, readonly=True, states={'draft':[('readonly',False)]}),
            'number_section': fields.related('section_id', 'number', type='integer', string='N° section', store=False)
}

class sale_order_section(osv.osv):

_name = 'sale.order.section'
_columns = {
            'order_line': fields.one2many('sale.order.line', 'section_id', 'Order Lines', readonly=False),
            'number': fields.integer('n° section', help='permet de décomposer le devis en sous-sections'),
            'order_id': fields.related('order_line', 'order_id', type="many2one", relation='sale.order', string="Order", readonly=True, required=True),
}
Avatar
Abbandona
Risposta migliore

Hi n@ilyk

as your Q, you can do like below :

you have inherit sale.order then put these 2 method

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

id=super(sale_order,self).create(cr,uid,vals,context)</t>
cid=self.pool.get('sale.order.section').create(cr,uid,{'order_id':id,'number':'sec0001'})
for i in self.browse(cr,uid,id).order_line:

self.poo.get('sale.order.line').write(cr,uid,[i.id],{'section_id':cid})
return id

Thanks

Avatar
Abbandona
Autore

Sorry : where i put this code ? in the sale_order_section class ?

in your inherited sale.order

Autore

ok but i don't understand where 'sec0001' come from . In fact, for each order line i have a column "number" where i put the number of section associated to the order line. Also, if i put the same number for 3 order lines for example, just one section has to be created. Thanks for your help

it was just a string which i put it , you can use your own no,,, for number in order line , i think you no need it because you have already a section Id , so why NUMBER ..... even you should use name of filed number as "name" then you can see section number in section Id , then you never need number in order line ,,,, as we have record id

Autore

Yes, it is the problem : i try to do 'number': order_line.number but it doesn't work. And a sale order is decomposed into multiples sections and here you create only one section ? I have number because if i write the same number for differents order lines, only one section is created

one sale order as one section Id am i right ??

Autore

no : one sale order has multiples sections (a section is a group of invoice lines), that is why i use a number ^^. However, a sale order line is associated with only one section

Risposta migliore

To override the create method just put your own create method in your sale.order.line class, in the following format:

    def create(self, cr, uid, vals, context=None):
         # Your additional code here
         return super(sale_order_line,self).create(cr,uid,vals,context)

The super(...) will ensure the original create method is still called and creates the object, while you code can add in any additional functionality you need.

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ago 22
7763
5
ott 18
6916
1
mar 15
8042
1
mar 15
6385
1
mar 15
5023