Browse Source

[MIG] base_import_match: Migration to 14.0

14.0
Jesus Ramoneda 4 years ago
parent
commit
812f855872
  1. 6
      base_import_match/README.rst
  2. 1
      base_import_match/models/base.py
  3. 7
      base_import_match/models/base_import.py
  4. 2
      base_import_match/tests/import_data/res_partner_dbid.csv
  5. 2
      base_import_match/tests/import_data/res_partner_external_id.csv
  6. 2
      base_import_match/tests/import_data/res_partner_invalid_combination_vat.csv
  7. 37
      base_import_match/tests/test_import.py
  8. 9
      base_import_match/views/base_import_match_view.xml

6
base_import_match/README.rst

@ -14,13 +14,13 @@ Base Import Match
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github
:target: https://github.com/OCA/server-backend/tree/13.0/base_import_match
:target: https://github.com/OCA/server-backend/tree/14.0/base_import_match
:alt: OCA/server-backend :alt: OCA/server-backend
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-backend-13-0/server-backend-13-0-base_import_match :target: https://translation.odoo-community.org/projects/server-backend-13-0/server-backend-13-0-base_import_match
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/253/13.0
:target: https://runbot.odoo-community.org/runbot/253/14.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -151,6 +151,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/13.0/base_import_match>`_ project on GitHub.
This module is part of the `OCA/server-backend <https://github.com/OCA/server-backend/tree/14.0/base_import_match>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

1
base_import_match/models/base.py

@ -35,6 +35,7 @@ class Base(models.AbstractModel):
if xmlid: if xmlid:
# Skip rows with ID, they do not need all this # Skip rows with ID, they do not need all this
row["id"] = xmlid row["id"] = xmlid
newdata.append(tuple(row[f] for f in clean_fields))
continue continue
elif dbid: elif dbid:
# Find the xmlid for this dbid # Find the xmlid for this dbid

7
base_import_match/models/base_import.py

@ -160,13 +160,16 @@ class BaseImportMatchField(models.Model):
) )
@api.depends("conditional", "field_id", "imported_value") @api.depends("conditional", "field_id", "imported_value")
def _compute_display_name(self):
def name_get(self):
result = []
for one in self: for one in self:
pattern = u"{name} ({cond})" if one.conditional else u"{name}" pattern = u"{name} ({cond})" if one.conditional else u"{name}"
one.display_name = pattern.format(
name = pattern.format(
name=one.field_id.name, name=one.field_id.name,
cond=one.imported_value, cond=one.imported_value,
) )
result.append((one.id, name))
return result
@api.onchange("field_id", "match_id", "conditional", "imported_value") @api.onchange("field_id", "match_id", "conditional", "imported_value")
def _onchange_match_id_name(self): def _onchange_match_id_name(self):

2
base_import_match/tests/import_data/res_partner_dbid.csv

@ -0,0 +1,2 @@
.id,vat,name
10,BE099999999,Deco Addict External DBID Changed

2
base_import_match/tests/import_data/res_partner_external_id.csv

@ -0,0 +1,2 @@
id,vat,name
base.res_partner_2,BE077777777,Deco Addict External ID Changed

2
base_import_match/tests/import_data/res_partner_invalid_combination_vat.csv

@ -0,0 +1,2 @@
name,vat,is_company
Deco Addict Changed,BE0477472701,False

37
base_import_match/tests/test_import.py

@ -27,6 +27,22 @@ class ImportCase(TransactionCase):
} }
) )
def test_res_partner_external_id(self):
"""Change name based on External ID."""
deco_addict = self.env.ref("base.res_partner_2")
record = self._base_import_record("res.partner", "res_partner_external_id")
record.do(["id", "vat", "name"], [], OPTIONS)
deco_addict.env.cache.invalidate()
self.assertEqual(deco_addict.name, "Deco Addict External ID Changed")
def test_res_partner_dbid(self):
"""Change name based on DB ID."""
deco_addict = self.env.ref("base.res_partner_2")
record = self._base_import_record("res.partner", "res_partner_dbid")
record.do([".id", "vat", "name"], [], OPTIONS)
deco_addict.env.cache.invalidate()
self.assertEqual(deco_addict.name, "Deco Addict External DBID Changed")
def test_res_partner_vat(self): def test_res_partner_vat(self):
"""Change name based on VAT.""" """Change name based on VAT."""
deco_addict = self.env.ref("base.res_partner_2") deco_addict = self.env.ref("base.res_partner_2")
@ -36,6 +52,17 @@ class ImportCase(TransactionCase):
deco_addict.env.cache.invalidate() deco_addict.env.cache.invalidate()
self.assertEqual(deco_addict.name, "Deco Addict Changed") self.assertEqual(deco_addict.name, "Deco Addict Changed")
def test_res_partner_invalid_combination_vat(self):
"""Change name based on VAT."""
deco_addict = self.env.ref("base.res_partner_2")
deco_addict.vat = "BE0477472701"
record = self._base_import_record(
"res.partner", "res_partner_invalid_combination_vat"
)
record.do(["name", "vat", "is_company"], [], OPTIONS)
deco_addict.env.cache.invalidate()
self.assertEqual(deco_addict.name, deco_addict.name)
def test_res_partner_parent_name_is_company(self): def test_res_partner_parent_name_is_company(self):
"""Change email based on parent_id, name and is_company.""" """Change email based on parent_id, name and is_company."""
record = self._base_import_record( record = self._base_import_record(
@ -63,6 +90,16 @@ class ImportCase(TransactionCase):
self.env.ref("base.res_partner_address_4").function, "Function Changed" self.env.ref("base.res_partner_address_4").function, "Function Changed"
) )
def test_res_partner_name_duplicated(self):
"""Change function based on name."""
record = self._base_import_record("res.partner", "res_partner_name")
partner_1 = self.env.ref("base.res_partner_address_4")
partner_2 = self.env.ref("base.res_partner_2")
function = partner_1.function
partner_2.name = partner_1.name
record.do(["function", "name"], [], OPTIONS)
self.assertEqual(self.env.ref("base.res_partner_address_4").function, function)
def test_res_users_login(self): def test_res_users_login(self):
"""Change name based on login.""" """Change name based on login."""
record = self._base_import_record("res.users", "res_users_login") record = self._base_import_record("res.users", "res_users_login")

9
base_import_match/views/base_import_match_view.xml

@ -69,6 +69,13 @@
</search> </search>
</field> </field>
</record> </record>
<act_window name="Import Match" res_model="base_import.match" id="match_action" />
<record id="match_action" model="ir.actions.act_window">
<field name="type">ir.actions.act_window</field>
<field name="name">Import Match</field>
<field name="res_model">base_import.match</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="match_menu" action="match_action" parent="base.next_id_9" /> <menuitem id="match_menu" action="match_action" parent="base.next_id_9" />
</odoo> </odoo>
Loading…
Cancel
Save