Return Dynamic Domain For Field In Odoo || Domain Based On Another Field In Odoo || Web Domain Field

  Рет қаралды 16,728

Odoo Mates

Odoo Mates

Күн бұрын

How to return dynamic domain based on fields in Odoo. Return domain based on other fields in Odoo. Domain based on fields in Odoo. How to set dynamic field domain in Odoo. Return field domain from computed function in odoo. Odoo dynamic domain. How to use web domain field module in Odoo. Odoo OCA webdomain field module.
Web Domain Field Module: odoo-community...
Github: github.com/OCA...
Part 1: • How To Give Domain For...
Usage
=====
When you define a view you can specify on the relational fields a domain
attribute. This attribute is evaluated as filter to apply when displaying
existing records for selection.
.. code-block:: xml
The value provided for the domain attribute must be a string representing a
valid Odoo domain. This string is evaluated on the client side in a
restricted context where we can reference as right operand the values of
fields present into the form and a limited set of functions.
In this context it's hard to build complex domain and we are facing to some
limitations as:
The syntax to include in your domain a criteria involving values from a
x2many field is complex.
The right side of domain in case of x2many can involve huge amount of ids
(performance problem).
Domains computed by an onchange on an other field are not recomputed when
you modify the form and don't modify the field triggering the onchange.
It's not possible to extend an existing domain. You must completely redefine
the domain in your specialized addon
etc...
In order to mitigate these limitations this new addon allows you to use the
value of a field as domain of an other field in the xml definition of your
view.
.. code-block:: python
product_id_domain = fields.Char(
compute="_compute_product_id_domain",
readonly=True,
store=False,
)
@api.multi
@api.depends('name')
def _compute_product_id_domain(self):
for rec in self:
rec.product_id_domain = json.dumps(
[('type', '=', 'product'), ('name', 'like', rec.name)]
)
Website: www.odoomates....
Github: github.com/odo...
Email : odoomates@gmail.com
Facebook: / odoomate
Twitter: / odoomates
Support Us in Ko Fi : ko-fi.com/odoo...

Пікірлер: 59
@Mathias-cq3zo
@Mathias-cq3zo 2 жыл бұрын
Ain't nothing like a good Odoo Mates video early in the morning along with coffee and toast hahaha, Thank u mate!!
@OdooMates
@OdooMates 2 жыл бұрын
sipping odoo in the morning :p Thanks for the support
@caim95able
@caim95able 3 жыл бұрын
you save my life everytime. I will never thank you enough
@OdooMates
@OdooMates 3 жыл бұрын
happy that it helps
@mohammedrai8197
@mohammedrai8197 3 жыл бұрын
Thanks, and well done for Odoo OCA modules tutorial's
@OdooMates
@OdooMates 3 жыл бұрын
thanks brother
@widitruth
@widitruth Жыл бұрын
I use Odoo Studio on Odoo SaaS/online, in my experience Studio can do many things in in xml level, but can we have solution of ths problem using Studio?
@maramazez8842
@maramazez8842 3 жыл бұрын
thanks.. i was searching for a days🙏
@OdooMates
@OdooMates 3 жыл бұрын
happy that it helped :)
@jesusbriceno9642
@jesusbriceno9642 2 жыл бұрын
It works like a charm. Thanks!
@OdooMates
@OdooMates 2 жыл бұрын
Glad it helped
@khriz571
@khriz571 7 ай бұрын
Tried in Odoo v16 and it's not working at all. Thanks anyways.
@lalamax3d
@lalamax3d Жыл бұрын
sir g, tussi kamal ho
@hectorstivalet
@hectorstivalet 3 жыл бұрын
Great method for v14 Mate, just two comments: - The addon module is nice but not a must have. The domain can be modified with an "attribute" xpath on the the field's domain to filter with the computed field present (and invisible) in the view: ('id', 'in', computed_filtered_ids)] - Multi is the default and implicit api for method in v14. It mustn't be explicitly written in v14, Odoo throws errors.
@OdooMates
@OdooMates 3 жыл бұрын
Thanks brother for the information
@irinakunstturnen2254
@irinakunstturnen2254 3 жыл бұрын
Congratulations, this is a very elegant solution. Maybe you can help me too, I've been searching the internet for hours. I have 14 locations and I want to define a filter that only shows these clients in the tree view who have the same location as the user, but I can't find what the syntax is: Unfortunately that does not work. Is there a trick for my solution? Many thanks for your help, Irina
@OdooMates
@OdooMates 3 жыл бұрын
@@irinakunstturnen2254 can you try using a computed field
@irinakunstturnen2254
@irinakunstturnen2254 3 жыл бұрын
@@OdooMates Thank you for your reponse! I've already tried that, unfortunately it doesn't work either
@OdooMates
@OdooMates 3 жыл бұрын
@@irinakunstturnen2254 can i see the code that you have tried
@ismailbenahmed3299
@ismailbenahmed3299 2 жыл бұрын
Hello Odoo Mates, I was searching for a while because I got that problem as you described. If you refresh all records are getting displayed instead of the filtered one. Is there any other solution instead of downloading a third custom modul. For example save the records in a list and display them with a loop?
@OdooMates
@OdooMates 2 жыл бұрын
this is the better and easy way right ?
@ismailbenahmed3299
@ismailbenahmed3299 2 жыл бұрын
@@OdooMates Yes. I have another issue, no one could help me yet : I have a custom module which I am trying to migrate from Odoo 13 Code to Odoo 15 code. But this module uses the python DOM library to create and filter XML entries. On Odoo 13 it is working fine and without problems. But in Odoo 15 somehow if you press read file to read the xml, I get a strange error : 'x.invoice' object attribute 'domtree' is read-only. Do you mates ever had a same issue or one related to that and can give me a hint ?
@blogic9811
@blogic9811 2 жыл бұрын
Hello, I hope you can help me: I'm using odoo enterprise 15 and want to return a dynamic field, a m2m field based on a m2o field
@learn-julia7215
@learn-julia7215 3 жыл бұрын
I follow the tutorials, but it seems that they are not in order. Where should I start?
@OdooMates
@OdooMates 3 жыл бұрын
the video are in order till video 10, new video adding to this series will be coming to the 11th position, the videos after video 10 is general videos in all the odoo versions
@yasminechenafa2088
@yasminechenafa2088 3 жыл бұрын
Thanks for your effort , but i still get this error "Uncaught TypeError: CreateListFromArrayLike called on non-object" any solution !
@OdooMates
@OdooMates 2 жыл бұрын
is it resolved ?
@addlin6122
@addlin6122 2 жыл бұрын
@@OdooMates I met the same problem. If I paste domain value it's can work.
@MrArian2
@MrArian2 2 жыл бұрын
@@OdooMates I get the same error in odoo 15
@chrissopulumaduka2659
@chrissopulumaduka2659 Жыл бұрын
Mehn this doesnt work for odoo 14 .......15
@renierferrer357
@renierferrer357 Жыл бұрын
Hi, any solution for this issue? I'm facing the same problem.
@amineabdelkrimaoudjehane4776
@amineabdelkrimaoudjehane4776 3 жыл бұрын
It works only for string, it doesn't work for date type (if the domain has a date type). I got an error "object of type date is not JSON serializable", I believe it is a Python error though
@OdooMates
@OdooMates 3 жыл бұрын
yes, even without this method we will not be able to give domain for a date or date time field right
@gsaladrigues
@gsaladrigues 2 жыл бұрын
cast your date as string --> ('date', '=', str(rec.date)
@erlanmaulanaibrahim9318
@erlanmaulanaibrahim9318 3 жыл бұрын
can you help me please? how to do it in odoo 14? why does the error appear? ValueError: Wrong value for sortir.operator_with_domain_ids: [["id", "in", [6, 18]]]
@OdooMates
@OdooMates 3 жыл бұрын
can i see the code you added
@learn-julia7215
@learn-julia7215 3 жыл бұрын
Why did the module change so much from 10-11 onwards? Training changed its style very quickly !!
@OdooMates
@OdooMates 3 жыл бұрын
The next video adding to odoo 14 series will be placed in the 11 th position, i hope you have reached us over the email,
@hasna4219
@hasna4219 3 жыл бұрын
👍
@OdooMates
@OdooMates 3 жыл бұрын
:)
@wilfredocristobalolanochav5789
@wilfredocristobalolanochav5789 3 жыл бұрын
Gracias
@OdooMates
@OdooMates 3 жыл бұрын
welcome :)
@ganca5128
@ganca5128 3 жыл бұрын
赞!!!
@OdooMates
@OdooMates 3 жыл бұрын
:)
@ANSAR-rw1lp
@ANSAR-rw1lp Жыл бұрын
i cant see the module in apps please help me
@OdooMates
@OdooMates Жыл бұрын
odoo-community.org/shop/web-domain-field-4368#attr=22677
@midhunsankar1
@midhunsankar1 2 жыл бұрын
How to do it without the module in odoo 15
@OdooMates
@OdooMates 2 жыл бұрын
did you tried using onchange ? what is the restriction to use this module ?
@saharahmed2319
@saharahmed2319 2 жыл бұрын
Great
@OdooMates
@OdooMates 2 жыл бұрын
welcome brother
@zerofusion4046
@zerofusion4046 2 жыл бұрын
How can we use dynamic domain for data with other models . This function works fine but with page refresh it shows all the data in list. how can we call other models recordset in json.dumps? @api.onchange("product_id") def _onchange_product_id_set_lot_domain(self): available_lot_ids = [] if self.product_id: quants = self.env["stock.quant"].read_group( [ ("product_id", "=", self.product_id.id), ("location_id", "child_of", self.location_id.id), ("quantity", ">", 0), ("lot_id", "!=", False), ], ["lot_id"], "lot_id", ) available_lot_ids = [quant["lot_id"][0] for quant in quants] self.lot_id = False return {"domain": {"lot_id": [("id", "in", available_lot_ids)]}}
@OdooMates
@OdooMates 2 жыл бұрын
if dependency is given correctly it will work without refresh
@zerofusion4046
@zerofusion4046 2 жыл бұрын
Hello Odoo Mates, I've tried but couldn't make it work. Could you please help out.
@OdooMates
@OdooMates 2 жыл бұрын
@@zerofusion4046 please share the compute function code and let us see whether there is proper dependency across models
@zerofusion4046
@zerofusion4046 2 жыл бұрын
​@@OdooMates what it does is that if i make delivery order and try to select lot no. of product it shows qty>0 only in onchange at add a line but if the line is already saved or generated by reserving it shows all the list. What am trying to do is that if any lot/serial no. has product_qty > 0 only then it has to list the lots/serial Enterprise(V13). how can we modify this code with json.dumps?? class StockMoveLine(models.Model): _inherit = "stock.move.line" lot_id_domain = fields.Char(compute="_compute_lot_id_domain", readonly=True, store=False) @api.depends('product_id') def _compute_lot_id_domain(self): quants = self.env["stock.quant"].search([('product_id', '=', self.product_id.id), ('location_id', 'child_of', self.location_id.id), ('quantity', '>', 0), ('lot_id', '!=', False)]) for rec in self: rec.lot_id_domain = json.dumps(quants) inherit.view.stock.move.line.detailed.operation.tree stock.move.line [('product_id','=', parent.product_id), ('company_id', '=', company_id), ('lot_id_domain')] it shows this error TypeError: Object of type 'stock.quant' is not JSON serializable
API Testing Using Postman | Crash Course
3:27:51
Mukesh otwani
Рет қаралды 99 М.
Don't look down on anyone#devil  #lilith  #funny  #shorts
00:12
Devil Lilith
Рет қаралды 44 МЛН
Who’s the Real Dad Doll Squid? Can You Guess in 60 Seconds? | Roblox 3D
00:34
Миллионер | 1 - серия
34:31
Million Show
Рет қаралды 2,6 МЛН
Difference between cookies, session and tokens
11:53
Valentin Despa
Рет қаралды 638 М.
How I'd Learn Web Development (If I Could Start Over)
6:55
Dylan's World
Рет қаралды 652 М.
OAuth 2.0 and OpenID Connect (in plain English)
1:02:17
OktaDev
Рет қаралды 1,7 МЛН