Skip to Content
Menu
This question has been flagged
2 Replies
5388 Views

I am trying to limit the BOMs that appear in a list based on products in a certain location, i have one function that executes sql to pull values from  the Bom and Bom_line tables to create a dictionary of related values. Then I compare this list with products in a location called WIP. and from that get a list of BOMs that should be available since their parts are available in the production environment. 

I have all of the code written my last step is to limit the BOM's that appear using a domain search for approved BOMS. my char value appears correctly. 

Code is below where enabled_boms appears as the char field correctly displaying [('id', '=', 9)]  in my app , which is correct, but appears as none.none when i print it in python. and then gives me Traceback:
Error: Expected attribute name, got (constant)


enabled_boms = fields.Char(compute='_compute_BOM_components')

print(enabled_boms)
BOM_production = fields.Many2one("mrp.bom", domain=enabled_boms)


I'm not sure how to get the returned value for enabled_boms to populate the domains section. 

my code runs if I hard code the

BOM_production = fields.Many2one('mrp.bom', domain = [('id', '=', 9)]) 


happy to share all of the code with whoever wants to take a look, just dont see value in posting it all here. 

Avatar
Discard

seems you need to return based on some field values selected ? see: https://www.youtube.com/watch?v=dq5Vtj_pwuI&t=819s

Author

Thanks @niyas, i followed the video and got it working with a hard coded domain however my dynamic domain causes this error.

Error:

Traceback:

TypeError: CreateListFromArrayLike called on non-object

at http://localhost:8069/web/content/556-d02db81/web.assets_backend.js:360:20

at Function._.each._.forEach (http://localhost:8069/web/content/555-da63a9d/web.assets_common.js:108:558)

at _.<computed> [as each] (http://localhost:8069/web/content/555-da63a9d/web.assets_common.js:165:526)

at eval_domains (http://localhost:8069/web/content/556-d02db81/web.assets_backend.js:357:265)

at Object.pyeval [as eval] (http://localhost:8069/web/content/556-d02db81/web.assets_backend.js:382:24)

at OdooClass.stringToArray (http://localhost:8069/web/content/556-d02db81/web.assets_backend.js:324:845)

at Class._getDomain (http://localhost:8069/web/content/556-d02db81/web.assets_backend.js:1504:167)

at Class._search (http://localhost:8069/web/content/556-d02db81/web.assets_backend.js:1097:607)

at http://localhost:8069/web/content/556-d02db81/web.assets_backend.js:1089:260

at Function._.each._.forEach (http://localhost:8069/web/content/555-da63a9d/web.assets_common.js:108:558)

I assume this is a formatting related issue or the value is not being passed to it as it says non-object.. Not sure what to do i have spent hours on this problem.

Did you find an answer for that ,because i have the same issue

Best Answer

in v16 this fix works for me.


replacing this:

result_domain.push.apply(result_domain, domain_array_to_combine);


for this:

try {
result_domain.push.apply(result_domain, domain_array_to_combine);
} catch (err) {
if (err.message.indexOf("CreateListFromArrayLike") !== -1) {
if (typeof (domain_array_to_combine) === "string") {
domain_array_to_combine = JSON.parse(domain_array_to_combine)
result_domain.push.apply(result_domain, domain_array_to_combine);
} else {
throw err;
}
} else {
throw err;
}
}
          

in file  .../addons/web/static/src/legacy/js/core/py_utils.js

Avatar
Discard
Best Answer

To resolve this issue, need to change in py_utils.js file.

function eval_domains(domains, evaluation_context) {
line no 164
From
result_domain.push.apply(result_domain, domain_array_to_combine);

to

result_domain.push.apply([result_domain, domain_array_to_combine]);   (apply args in array)


need to override eval_domains method and change code.



Avatar
Discard
Related Posts Replies Views Activity
0
Feb 20
4042
0
Oct 18
2700
2
Jul 25
321
2
Aug 24
4130
1
Mar 24
1900