Great tutorial I think its also worth noting, Odoo is going to sequentially execute each tuple in the list for One2many field. Adding the possibility to NOT only create new or replace exist.
Hi, (0, 0, { values }) link to a new record that needs to be created with the given values dictionary (1, ID, { values }) update the linked record with id = ID (write *values* on it) (2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well) (3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself) (4, ID) link to existing record with id = ID (adds a relationship) (5) unlink all (like using (3,ID) for all linked records) (6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs) Explain what the use of all of this. Just little bit confused.
very nice, great explaination, this will be very useful... can i add a Many2one type Transient field in model? if yes, how i can create in Model and use it in view, I do not want to store its data in database. AND please also give the link of your video for adding Sequence for a field, as i forgot what was the link actually. be blessed :)
Hello, I have three fields ex: request_qty = 4, deliver_qty = 4 and total_qty = 0, how can i automatically add deliver_qty values to total_qty . Because i want users to always request for stock qty after sales and once manager deliver_qty is should automatically add up on user total_qty field. How can i achieve this function?
Added One2many in crm lead form page as a notebook page. now i want to show this One2many fields value into sale order One2many fields. can you help me
i cant watch "all" of the video right now sadly, but i wanted to ask the question before i forget every time u select a product template u add "1" product, can we have for example a package template, when i choose it it will automatically add the package productS .. for example i want to send supplies i can choose the supply package which includes stocks and shipping or i want to do a training, so i need hall booking, refreshments, perdiam for each participants, etc etc
These are two tables in Odoo to handle product and product variants... For every record in product template you will have atleast one record in product. Product
In this video,one2 many updated accordingly to the specific many 2 one field.I am change the onchange many 2one filed to many2many.Data is fetched to the one2 many line but not able to save.It shows no implement error How can I done that?.pls reply :)
Why when adding all records is erased and only one is added? @api.onchange('idtrans') def _onchange_idtrans(self): for rec in self: lines = [(5, 0, 0)] # lines = [] for line in self.idtrans: print('type', type(line)) print('type_id',type(line.id)) val = { 'idtrans':line.id, 'amount': 5, 'date': datetime.today() } lines.append((0, 0, val)) print('lines_new:',lines) rec.idpayamount = lines
@@OdooMates I tried what she told me and the problem still exists lines=[] val = { 'idtrans': self.idtrans.id, 'amount': 5, 'date': datetime.today() } lines.append((0, 0, val)) self.idpayamount = lines
I have a model with me in which a one2many field of products is added below the many2one field of customer. i need this one2many field of product lines to be automatically fetched when i select the particular customer in another module. How can I do this with the onchange function? please help me ASAP
@@OdooMates i have a model with customer details (name, company etc ) and a one2many field below that (it is defined as a separate model). After that when i choose the customer details say customer name in another module say like sale module (sale order form) , the earlier one2many field must be automatically coming.....
I coundnt add lines. only replacing with existing lines @api.onchange('app_order_ids') def on_change_app_id(self): for rec in self: lines = [] for line in self.app_order_ids.top_lines: val={'article_name':line.name} lines.append((0,0,val)) rec.grn_order_lines = lines
I am facing a problem I am using the code from this tutorial to add a product to the `recurring_invoice_line_ids` in sale.subscription but I am going this error `(Record: product.product(154,), User: 2)`(Record: product.product(154,), User: 2)
self.env['product.template'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1) change product.template to product.product and see
if you activate developer mode and navigate go to Settings -> Technical -> Database Structure -> Models, search for the models and open it, then you can see all the fields/columns in the table/model
hello, i had a problem with that class parent() field category_id many2one product.category field child_ids one2many class child () field parent_id many2one field product many2one product.template in xml or py in need to filter the product to; select product from its category how to pass domain?
@@OdooMates i folowed the tuto and i trie to do the same thing into my project like this: class fleet_carnet_essnece_ayoub(models.Model): _name = 'fleet_affectation_ayoub.fleet_carnet_essnece_ayoub' _description = ' Creation carnet de bons d essence' ...............
Many2one_carnet_field = fields.Many2one ('fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub') class fleet_bon_essnece_ayoub(models.Model): _name = 'fleet_affectation_ayoub.fleet_bon_essnece_ayoub' _description = " Bons d'essence" .................................. carnet = fields.Many2one ('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', string ='Carnet', required="True") bon_line = fields.One2many ('fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub', 'carnet_ids', string ="Ligne de bons") @api.onchange('carnet') def on_change_carnet(self): for rec in self: lines =[] print ("self.carnet", self.carnet.on2many_carnet_field ) # for line in self.carnet rec.bon_line = lines class fleet_creation_bon_essnece_ayoub(models.Model): _name = 'fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub' _description = 'ligne des bons ' bon_qty = fields.Integer(string="Quantity") carnet_ids = fields.Many2one('fleet_affectation_ayoub.fleet_bon_essnece_ayoub', string='joined') bon_id = fields.Integer(string="Numero de bon") carnet_id = fields.Many2one('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', string='joined') on2many_carnet_field = fields.One2many('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', 'Many2one_carnet_field', string='joined') and i recieved the folowing error : File "/opt/odoo/odoo-10.0/addons/fleet_affectation_ayoub/models/models.py", line 234, in on_change_carnet print ("self.carnet", self.carnet.on2many_carnet_field ) AttributeError: 'fleet_affectation_ayoub.fleet_carnet_essnece_ayoub' object has no attribute 'on2many_carnet_field' Also i want to know the way that you retriev values from product.variant Thankyou brother
@@thanshidhap.p4743 then take a copy of one2many field definition from the first model and place it in the second model/class, the only thing that you need to change is the many2one field
Great tutorial
I think its also worth noting, Odoo is going to sequentially execute each tuple in the list for One2many field.
Adding the possibility to NOT only create new or replace exist.
I hardly subscribe to any channel. But you are really doing a great job. Keep it up! I hope to learn a lot from you.
Thanks and welcome
Hi,
(0, 0, { values }) link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) update the linked record with id = ID (write *values* on it)
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID) link to existing record with id = ID (adds a relationship)
(5) unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)
Explain what the use of all of this. Just little bit confused.
Super usefull! i was just trying to write one2many field in a wizard, and i had no idea about how to do this! thanks!
Glad it helped!
Thanks for making this video. :D
Welcome :)
Thank u so much. Very helpful
welcome brother
Great tutorial
Glad you think so!
Thank you!
You're welcome!
very nice, great explaination, this will be very useful... can i add a Many2one type Transient field in model? if yes, how i can create in Model and use it in view, I do not want to store its data in database. AND please also give the link of your video for adding Sequence for a field, as i forgot what was the link actually. be blessed :)
Hello, I have three fields ex: request_qty = 4, deliver_qty = 4 and total_qty = 0, how can i automatically add deliver_qty values to total_qty . Because i want users to always request for stock qty after sales and once manager deliver_qty is should automatically add up on user total_qty field. How can i achieve this function?
Added One2many in crm lead form page as a notebook page. now i want to show this One2many fields value into sale order One2many fields. can you help me
create a one2many in sale order model, and pass the value from the crm lead to sale order via sale order creation method in lead
@@OdooMates ok thanks I will try. Is there any video or documents for the same?
@@surekhapalani6511 not specifically for this, but if we have strong idea in odoo orm, it is easy, ua-cam.com/video/8V-uOG8KkKA/v-deo.html
Do you have away to post chatter tracking in product order line in field one two many ??
i cant watch "all" of the video right now sadly, but i wanted to ask the question before i forget
every time u select a product template u add "1" product, can we have for example a package template, when i choose it it will automatically add the package productS .. for example i want to send supplies
i can choose the supply package which includes stocks and shipping
or i want to do a training, so i need hall booking, refreshments, perdiam for each participants, etc etc
yes you can add multiple products at a time, thats why we have used for loop, it is shown in the video itself, if you watch fully, you can see it :)
@@OdooMates thank you for the confirmation , awesome!
ok what is the difference between this and related?
If you use related you might can fill just one field..
@@OdooMates this right. great
Hello Sir, What is the difference between product_product and product_template?. It is so confused for me. :)
These are two tables in Odoo to handle product and product variants... For every record in product template you will have atleast one record in product. Product
In this video,one2 many updated accordingly to the specific many 2 one field.I am change the onchange many 2one filed to many2many.Data is fetched to the one2 many line but not able to save.It shows no implement error How can I done that?.pls reply :)
can you show your code please
@@OdooMates
class Billingrateform(models.Model): _name = "billing.rate" _rec_name = 'project_id' project_id = fields.Many2one('account.analytic.account', string="Project") billing_date = fields.Date(string="Date", default=datetime.today()) start_date = fields.Date(string='Start date') end_date = fields.Date(string='End date') days_id = fields.Float(string='Days', compute='_compute_worked_days', store=True, readonly=True) demos_id = fields.One2many("billing.tree", "line_id") @api.onchange('project_id') def _check_employee_id(self): for rec in self: lines= [(5, 0, 0)] for line in self.project_id.line_ids: vals = { 'employee_id': line.employee_id, 'unit_amount': line.unit_amount, 'cost_id': line.timesheet_cost_id / 100 * line.add_cost + line.timesheet_cost_id, 'timesheet_cost': line.timesheet_cost_id, 'oper_cost': line.add_cost, 'percentage_id': line.timesheet_cost_id / 100 * line.add_cost, 'total_id': line.timesheet_cost_id * line.unit_amount + line.timesheet_cost_id / 100 * line.add_cost } lines.append((0, 0, vals)) rec.demos_id = lines print(lines, "val")
I dont know which way I can present the code.Can you give me a mail.
I also faced same problem. Later if noticed that one2many field was readonly therefore I put force_save="1"
But at the time of saving all the records under one2many field is removing. Why?
Why when adding all records is erased and only one is added?
@api.onchange('idtrans')
def _onchange_idtrans(self):
for rec in self:
lines = [(5, 0, 0)]
# lines = []
for line in self.idtrans:
print('type', type(line))
print('type_id',type(line.id))
val = {
'idtrans':line.id,
'amount': 5,
'date': datetime.today()
}
lines.append((0, 0, val))
print('lines_new:',lines)
rec.idpayamount = lines
Remove this line lines = [(5, 0, 0)]
and simply give [] and see
@@OdooMates I tried what she told me and the problem still exists
lines=[]
val = {
'idtrans': self.idtrans.id,
'amount': 5,
'date': datetime.today()
}
lines.append((0, 0, val))
self.idpayamount = lines
Hi,
How can i onchange the one2many fields depending on the other page one2many fields?could you please help
Hello. how to get bydefault all medicines when many2one field is blank?
in the one2many lines ? see: ua-cam.com/video/BSL4iOHZ-Rc/v-deo.html
Sir, could you tell me how to delete unsaved newobject id lines in onchange.
Will this help ? ua-cam.com/video/2pOIxhE_xuY/v-deo.html
I have a model with me in which a one2many field of products is added below the many2one field of customer. i need this one2many field of product lines to be automatically fetched when i select the particular customer in another module. How can I do this with the onchange function? please help me ASAP
is the onchange of the customer happening in the same model that contains the one2many field ?
@@OdooMates i have a model with customer details (name, company etc ) and a one2many field below that (it is defined as a separate model). After that when i choose the customer details say customer name in another module say like sale module (sale order form) , the earlier one2many field must be automatically coming.....
By an onchange function you can achieve it
Unable to add below record to one2Many on compute method in Odoo 13.
[(5, 0, 0), (0, 0, {'employee_id': 'Mitchell Admin', 'worked_hours': 10.0030555555556, 'percentage': 0})]
------------------------------------------------------------------------------------------------------------------------------------------------
detail_list = fields.One2many('ndr.project.detail', 'project_name', string='Details',
compute='_calculate_project_details')
------------------------------------------------------------------------------------------------------------------------------------------------
You have any error message ?
How can we update salesorderline with details from my custom module?
if you have sale.order.line object, using object.field_name = 'value' or object.write({'field': value}) , you can update the record
@@OdooMates Can u try to make a video on that,onchange in existing views like saleorderline
@@vrindhavinoj2222 hope you already achieved as per mail conversation
@@OdooMates Yes sir..
im having same problem. can you explain to me what is the solution.
I coundnt add lines. only replacing with existing lines
@api.onchange('app_order_ids')
def on_change_app_id(self):
for rec in self:
lines = []
for line in self.app_order_ids.top_lines:
val={'article_name':line.name}
lines.append((0,0,val))
rec.grn_order_lines = lines
version ?
@@OdooMates 10.0
any solution for version 10?
@@ashwinstephen7292 the above video was illustrated in v12
For V10, try as follows:
vals = {
'field_1': value,
'field_2': value,
}
self.one2_many_field_name += self.one2_many_field_name.new(vals)
I am facing a problem
I am using the code from this tutorial to
add a product to the `recurring_invoice_line_ids` in sale.subscription
but I am going this error `(Record: product.product(154,), User: 2)`(Record: product.product(154,), User: 2)
Can you show ur codes
I tried asking on odoo form and stackoverflow but not one is answering me can u plz help
@@OdooMates
supsctiption_pak = self.env['product.template'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1)
supsctiption_info = {
'partner_id': vals['name'],
}
add_supsctiption = self.env['sale.subscription'].create(supsctiption_info)
print('sb',supsctiption_pak.name)
print('sb1',vals['name'])
# print('sb2',vals['name'].name)
supsctiption_to_pak = self.env['sale.subscription'].search([('partner_id', '=', vals['name'])], limit=1)
print('sb3',supsctiption_to_pak)
print('sb3',supsctiption_to_pak.display_name)
add_supsctiption_pak = {
'product_id': supsctiption_pak,
}
supsctiption_to_pak.write({'recurring_invoice_line_ids':[(5, 0, 0),(0,0,add_supsctiption_pak)]})
@@OdooMates
I am using the create function from my custom module
since on-change Is only cared from the UI
self.env['product.template'].search([('name', '=', pak_name),('recurring_invoice', '=', True)], limit=1) change product.template to product.product and see
what are the columns in the odoo AccountType master , documentType master and how these are accessed in a code ?
if you activate developer mode and navigate go to Settings -> Technical -> Database Structure -> Models, search for the models and open it, then you can see all the fields/columns in the table/model
Hi i need to update data from fields i input without use many2one in product_id can you display that?
Thanks 😊
can you elaborate little more
hello,
i had a problem with that
class parent()
field category_id many2one product.category
field child_ids one2many
class child ()
field parent_id many2one
field product many2one product.template
in xml or py
in need to filter the product to; select product from its category
how to pass domain?
Like this,I want to add more products,can you help me in this
Thank you.
hello I would like to do the same but do it from one One2Many to another One2many
Please Make js video
Will be publishing today :)
please leave me here the link to the git repesotery
github.com/odoomates/odooapps
github.com/odoomates/Development-Tutorials
@@OdooMates thankyou for this tutorial, Algeria :)
@@dzaround welcome from India :)
@@OdooMates i folowed the tuto and i trie to do the same thing into my project like this:
class fleet_carnet_essnece_ayoub(models.Model):
_name = 'fleet_affectation_ayoub.fleet_carnet_essnece_ayoub'
_description = ' Creation carnet de bons d essence'
...............
Many2one_carnet_field = fields.Many2one ('fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub')
class fleet_bon_essnece_ayoub(models.Model):
_name = 'fleet_affectation_ayoub.fleet_bon_essnece_ayoub'
_description = " Bons d'essence"
..................................
carnet = fields.Many2one ('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', string ='Carnet', required="True")
bon_line = fields.One2many ('fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub', 'carnet_ids', string ="Ligne de bons")
@api.onchange('carnet')
def on_change_carnet(self):
for rec in self:
lines =[]
print ("self.carnet", self.carnet.on2many_carnet_field )
# for line in self.carnet
rec.bon_line = lines
class fleet_creation_bon_essnece_ayoub(models.Model):
_name = 'fleet_affectation_ayoub.fleet_creation_bon_essnece_ayoub'
_description = 'ligne des bons '
bon_qty = fields.Integer(string="Quantity")
carnet_ids = fields.Many2one('fleet_affectation_ayoub.fleet_bon_essnece_ayoub', string='joined')
bon_id = fields.Integer(string="Numero de bon")
carnet_id = fields.Many2one('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', string='joined')
on2many_carnet_field = fields.One2many('fleet_affectation_ayoub.fleet_carnet_essnece_ayoub', 'Many2one_carnet_field', string='joined')
and i recieved the folowing error :
File "/opt/odoo/odoo-10.0/addons/fleet_affectation_ayoub/models/models.py", line 234, in on_change_carnet
print ("self.carnet", self.carnet.on2many_carnet_field )
AttributeError: 'fleet_affectation_ayoub.fleet_carnet_essnece_ayoub' object has no attribute 'on2many_carnet_field'
Also i want to know the way that you retriev values from product.variant
Thankyou brother
how to calculate the entered value in one2many field (example:in this video how to calculate that quantity of product in total)
ua-cam.com/video/0mHM_EPT6Fw/v-deo.html
ua-cam.com/video/8V-uOG8KkKA/v-deo.html
not working, is the same and i get newID object
How can i inherit the same One2many field in different class? Please help me
just change the connecting many2one field
@@OdooMates i can't get you. I want to use the same one2many field in another submenu. Can u describe me
@@thanshidhap.p4743 is it in the same model or different model ?
@@OdooMates different class, same py file
@@thanshidhap.p4743 then take a copy of one2many field definition from the first model and place it in the second model/class, the only thing that you need to change is the many2one field
HAHA let's make crap ORM with magic numbers and shit documentation - some Odoo dev probably
You mean video not helpful ?