Repository: teamgeek-io/flask-odoo

Issue:
Odoo model's write is called with invalid arguments

Discussion:

Patch:
diff --git a/src/flask_odoo/model.py b/src/flask_odoo/model.py
index df1ab49..0edc1cb 100644
--- a/src/flask_odoo/model.py
+++ b/src/flask_odoo/model.py
@@ -56,11 +56,12 @@ def create_or_update(self):
         ):
             vals.pop(key, None)
         elif isinstance(field, Many2oneType):
-            vals[key] = vals[key][0]
+            if key in vals:
+                vals[key] = vals[key][0]
         else:
             pass
     if self.id:
-        self._odoo[model_name].write([self.id, vals])
+        self._odoo[model_name].write([self.id], vals)
     else:
         self.id = self._odoo[model_name].create(vals)
 


Test patch:
diff --git a/tests/test_model.py b/tests/test_model.py
index d58ff5d..1146699 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -181,7 +181,7 @@ def test_base_model_create_or_update(app, app_context):
         "admin",
         "res.partner",
         "write",
-        ([2, {"name": "new_name"}],),
+        ([2], {"name": "new_name"}),
         {},
     )