[IMP] onchange_helper: black, isort
parent
d2fe84bc3e
commit
1f6904694a
|
@ -2,14 +2,13 @@
|
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
'name': 'Onchange Helper',
|
||||
'version': '12.0.1.0.0',
|
||||
'summary': 'Technical module that ease execution'
|
||||
' of onchange in Python code',
|
||||
'author': 'Akretion,Camptocamp,Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/OCA/server-tools',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Generic Modules',
|
||||
'depends': ['base'],
|
||||
'installable': True,
|
||||
"name": "Onchange Helper",
|
||||
"version": "12.0.1.0.0",
|
||||
"summary": "Technical module that ease execution" " of onchange in Python code",
|
||||
"author": "Akretion,Camptocamp,Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/server-tools",
|
||||
"license": "AGPL-3",
|
||||
"category": "Generic Modules",
|
||||
"depends": ["base"],
|
||||
"installable": True,
|
||||
}
|
||||
|
|
|
@ -6,16 +6,16 @@ from odoo import api, models
|
|||
|
||||
|
||||
class Base(models.AbstractModel):
|
||||
_inherit = 'base'
|
||||
_inherit = "base"
|
||||
|
||||
@api.model
|
||||
def _get_new_values(self, record, on_change_result):
|
||||
vals = on_change_result.get('value', {})
|
||||
vals = on_change_result.get("value", {})
|
||||
new_values = {}
|
||||
for fieldname, value in vals.items():
|
||||
if fieldname not in record:
|
||||
column = self._fields[fieldname]
|
||||
if value and column.type == 'many2one':
|
||||
if value and column.type == "many2one":
|
||||
value = value[0] # many2one are tuple (id, name)
|
||||
new_values[fieldname] = value
|
||||
return new_values
|
||||
|
@ -33,9 +33,7 @@ class Base(models.AbstractModel):
|
|||
# _onchange_spec() will return onchange fields from the default view
|
||||
# we need all fields in the dict even the empty ones
|
||||
# otherwise 'onchange()' will not apply changes to them
|
||||
onchange_specs = {
|
||||
field_name: '1' for field_name, field in self._fields.items()
|
||||
}
|
||||
onchange_specs = {field_name: "1" for field_name, field in self._fields.items()}
|
||||
all_values = values.copy()
|
||||
# If self is a record (play onchange on existing record)
|
||||
# we take the value of the field
|
||||
|
|
|
@ -6,31 +6,27 @@ from odoo.tests.common import TransactionCase
|
|||
|
||||
class TestOnchangeHelper(TransactionCase):
|
||||
def test01_partner_parent(self):
|
||||
main_partner = self.env.ref('base.main_partner')
|
||||
input_vals = dict(parent_id=main_partner.id, type='contact')
|
||||
updated_vals = self.env['res.partner'].play_onchanges(
|
||||
input_vals, ['parent_id']
|
||||
)
|
||||
self.assertIn('country_id', updated_vals)
|
||||
self.assertIn('state_id', updated_vals)
|
||||
self.assertIn('street', updated_vals)
|
||||
self.assertIn('zip', updated_vals)
|
||||
main_partner = self.env.ref("base.main_partner")
|
||||
input_vals = dict(parent_id=main_partner.id, type="contact")
|
||||
updated_vals = self.env["res.partner"].play_onchanges(input_vals, ["parent_id"])
|
||||
self.assertIn("country_id", updated_vals)
|
||||
self.assertIn("state_id", updated_vals)
|
||||
self.assertIn("street", updated_vals)
|
||||
self.assertIn("zip", updated_vals)
|
||||
|
||||
self.assertEqual(
|
||||
updated_vals['country_id'], main_partner.country_id.id
|
||||
)
|
||||
self.assertEqual(updated_vals['state_id'], main_partner.state_id.id)
|
||||
self.assertEqual(updated_vals['street'], main_partner.street)
|
||||
self.assertEqual(updated_vals['zip'], main_partner.zip)
|
||||
self.assertEqual(updated_vals["country_id"], main_partner.country_id.id)
|
||||
self.assertEqual(updated_vals["state_id"], main_partner.state_id.id)
|
||||
self.assertEqual(updated_vals["street"], main_partner.street)
|
||||
self.assertEqual(updated_vals["zip"], main_partner.zip)
|
||||
|
||||
def test02_partner_country(self):
|
||||
partner_demo = self.env.ref('base.partner_demo')
|
||||
input_vals = {'country_id': self.env.ref('base.us').id}
|
||||
updated_vals = partner_demo.play_onchanges(input_vals, ['country_id'])
|
||||
self.assertIn('country_id', updated_vals)
|
||||
partner_demo = self.env.ref("base.partner_demo")
|
||||
input_vals = {"country_id": self.env.ref("base.us").id}
|
||||
updated_vals = partner_demo.play_onchanges(input_vals, ["country_id"])
|
||||
self.assertIn("country_id", updated_vals)
|
||||
|
||||
def test_playing_onchange_on_model(self):
|
||||
result = self.env['res.partner'].play_onchanges(
|
||||
{'company_type': 'company'}, ['company_type']
|
||||
result = self.env["res.partner"].play_onchanges(
|
||||
{"company_type": "company"}, ["company_type"]
|
||||
)
|
||||
self.assertEqual(result['is_company'], True)
|
||||
self.assertEqual(result["is_company"], True)
|
||||
|
|
Loading…
Reference in New Issue