diff --git a/README.md b/README.md index e2e89e1..04df660 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ partner.update({'mobile': '12345678'}) ``` - Search for Records ```python -partner_ids = odoo.env['res.partner'].search(domain=[('name', '=', 'Abigail Peterson')]) +partner_ids = odoo.env['res.partner'].search([('name', '=', 'Abigail Peterson')]) print(partner_ids) #[50] ``` @@ -77,8 +77,19 @@ print(new_partner_id) ``` - Update Records ```python +#These are the ways to update records +partner.mobile = '+91 9746707744' +partner.write({'mobile': '+91 9746707744'}) odoo.env['res.partner'].write(ids=new_partner_id, values={'phone': '1234567890'}) ``` +- Update Relation fields (One2many or Many2many) +```python +from pyodoo_connect import Command +partner.category_id = [Command.set([5,6])] +partner.write({'category_id': [Command.link([4,3])]}) +odoo.env['res.partner'].write(ids=new_partner_id, values={'category_id': [Command.create({'name': 'New Tag'})]}) +#All functions of Command can be used (create, update, delete, unlink, link, clear, set) +``` - Delete Records ```python odoo.env['res.partner'].unlink(ids=new_partner_id) @@ -92,6 +103,11 @@ odoo.download_report(report_name='sale.report_saleorder', record_ids=[52], file_ print(odoo.version) #17.0 ``` +- UID +```python +print(odoo.uid) +#2 +``` - User Context ```python print(odoo.env.context) diff --git a/pyodoo_connect/proxies.py b/pyodoo_connect/proxies.py index e01fb1f..46fc799 100644 --- a/pyodoo_connect/proxies.py +++ b/pyodoo_connect/proxies.py @@ -14,6 +14,8 @@ def __init__(self, model_proxy, record_id, method_name): self.method_name = method_name def __call__(self, *args, **kwargs): + if self.method_name == 'write': + self.method_name = 'update' # If there are positional arguments, assume the first is a dictionary and reformat as needed if args and isinstance(args[0], dict): kwargs = {'values': args[0]} # Override kwargs with values from args @@ -101,7 +103,6 @@ def search_read(self, domain: list, fields: list): return self.odoo.call("object", "execute", self.model_name, 'search_read', domain, fields) def write(self, ids: list, values: dict): - print(values) return self.odoo.call("object", "execute", self.model_name, 'write', ids, values) def unlink(self, ids: list):