Skip to content

Commit 7040bee

Browse files
committed
Merge PR #52 into 18.0
Signed-off-by ValentinVinagre
2 parents 5b2c7b2 + 3785d6f commit 7040bee

24 files changed

Lines changed: 1206 additions & 0 deletions
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
==============================
2+
Partner Code Program Territory
3+
==============================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:09dd0e54b316a68e2d7f37c7ca19c76064ffe10b768f9728fec696b19b0dccdf
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-sygel--technology%2Fsy--partner--contact-lightgray.png?logo=github
20+
:target: https://github.com/sygel-technology/sy-partner-contact/tree/18.0/partner_code_program_territory
21+
:alt: sygel-technology/sy-partner-contact
22+
23+
|badge1| |badge2| |badge3|
24+
25+
This module adds the partner code program territory model, a new field
26+
in the res partner address that would be added to all the countries
27+
address format.
28+
29+
**Table of contents**
30+
31+
.. contents::
32+
:local:
33+
34+
Installation
35+
============
36+
37+
To install this module, you need to:
38+
39+
- Only install
40+
41+
Configuration
42+
=============
43+
44+
To configure this module, you need to:
45+
46+
- Only install
47+
48+
Usage
49+
=====
50+
51+
To use this module, you need to:
52+
53+
1. Create new program territory codes in *Contacts > Configuration >
54+
Code Program Territories*
55+
2. Edit the code program territory of a partner of type company in the
56+
address field of the partner form
57+
58+
Bug Tracker
59+
===========
60+
61+
Bugs are tracked on `GitHub Issues <https://github.com/sygel-technology/sy-partner-contact/issues>`_.
62+
In case of trouble, please check there if your issue has already been reported.
63+
If you spotted it first, help us to smash it by providing a detailed and welcomed
64+
`feedback <https://github.com/sygel-technology/sy-partner-contact/issues/new?body=module:%20partner_code_program_territory%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
65+
66+
Do not contact contributors directly about support or help with technical issues.
67+
68+
Credits
69+
=======
70+
71+
Authors
72+
-------
73+
74+
* Sygel
75+
76+
Contributors
77+
------------
78+
79+
- `Sygel <https://www.sygel.es>`__:
80+
81+
- Valentín Vinagre
82+
- Alberto Martínez
83+
84+
Maintainers
85+
-----------
86+
87+
This module is part of the `sygel-technology/sy-partner-contact <https://github.com/sygel-technology/sy-partner-contact/tree/18.0/partner_code_program_territory>`_ project on GitHub.
88+
89+
You are welcome to contribute.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from . import models
4+
from .hooks import post_init_hook, uninstall_hook
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2024 Alberto Martínez <alberto.martinez@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Partner Code Program Territory",
5+
"summary": "Adds the partner code program territory fields on contacts",
6+
"version": "18.0.1.0.0",
7+
"category": "Partner Management",
8+
"website": "https://github.com/sygel-technology/sy-partner-contact",
9+
"author": "Sygel",
10+
"license": "AGPL-3",
11+
"application": False,
12+
"installable": True,
13+
"depends": [
14+
"partner_code_program",
15+
],
16+
"data": [
17+
"security/ir.model.access.csv",
18+
"views/res_partner_code_program_territory_views.xml",
19+
"views/res_partner_code_program_views.xml",
20+
"views/res_partner_views.xml",
21+
],
22+
"post_init_hook": "post_init_hook",
23+
"uninstall_hook": "uninstall_hook",
24+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2024 Alberto Martínez <alberto.martinez@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
import logging
4+
5+
6+
def _edit_address_format(country, inserted_field, reference_field, mode="after"):
7+
"""Inserts a text in the address format of a country
8+
country
9+
inserted_field: field to insert.'
10+
reference_field: reference address field
11+
mode: after or before. Insert text after or before the reference field
12+
returns: True if sucess. False if failure
13+
"""
14+
country.ensure_one()
15+
if mode not in ["after", "before"]:
16+
raise Exception("Mode should be 'after' or 'before'")
17+
if ")s" not in inserted_field:
18+
inserted_field = f"%({inserted_field})s"
19+
if ")s" not in reference_field:
20+
reference_field = f"({reference_field})s"
21+
22+
separator = "\n"
23+
address_splitted = country.address_format.split(separator)
24+
try:
25+
position = next(
26+
i for i, v in enumerate(address_splitted) if reference_field in v
27+
)
28+
except Exception:
29+
return False
30+
if mode == "after":
31+
position += 1
32+
address_splitted.insert(position, inserted_field)
33+
country.address_format = separator.join(address_splitted)
34+
return True
35+
36+
37+
def post_init_hook(env):
38+
inserted_field = "code_program_territory_name"
39+
operations = [
40+
("code_program_name", "before"),
41+
]
42+
countries = env["res.country"].search([])
43+
for country in countries:
44+
sucess = False
45+
i = 0
46+
while not sucess and i < len(operations):
47+
sucess = _edit_address_format(
48+
country, inserted_field, operations[i][0], operations[i][1]
49+
)
50+
i += 1
51+
if not sucess:
52+
logging.error("{country.name}'s address could not be edited")
53+
54+
55+
def uninstall_hook(env):
56+
fields = ["code_program_territory_name", "code_program_territory_id"]
57+
countries = env["res.country"].search([])
58+
for country in countries:
59+
country_address = country.address_format
60+
for field in fields:
61+
formatted_field = f"%({field})s"
62+
country_address = country_address.replace(formatted_field, "")
63+
country_address = country_address.replace("\n\n", "\n")
64+
country.address_format = country_address
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * partner_code_program_territory
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 17.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2024-06-10 16:15+0000\n"
10+
"PO-Revision-Date: 2024-06-10 16:15+0000\n"
11+
"Last-Translator: \n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: partner_code_program_territory
19+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__code
20+
msgid "Code"
21+
msgstr "Código"
22+
23+
#. module: partner_code_program_territory
24+
#: model:ir.model,name:partner_code_program_territory.model_res_partner_code_program
25+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__code_program_id
26+
msgid "Code Program"
27+
msgstr "Código de programa"
28+
29+
#. module: partner_code_program_territory
30+
#: model_terms:ir.ui.view,arch_db:partner_code_program_territory.res_partner_code_program_form_view_inherit_territory
31+
msgid "Code Program Territories"
32+
msgstr "Códigos de territorio"
33+
34+
#. module: partner_code_program_territory
35+
#. odoo-python
36+
#: code:addons/partner_code_program_territory/models/res_partner_code_program.py:0
37+
#: model:ir.model,name:partner_code_program_territory.model_res_partner_code_program_territory
38+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner__code_program_territory_id
39+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program__code_program_territory_ids
40+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory_mixin__code_program_territory_id
41+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_users__code_program_territory_id
42+
#: model_terms:ir.ui.view,arch_db:partner_code_program_territory.view_res_partner_filter_code_program_territory
43+
#, python-format
44+
msgid "Code Program Territory"
45+
msgstr "Código de territorio"
46+
47+
#. module: partner_code_program_territory
48+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner__code_program_territory_name
49+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_users__code_program_territory_name
50+
msgid "Code Program Territory Name"
51+
msgstr "Nombre del código de territorio"
52+
53+
#. module: partner_code_program_territory
54+
#: model_terms:ir.ui.view,arch_db:partner_code_program_territory.view_partner_form_code_program_territory
55+
msgid "Code Program Territory..."
56+
msgstr "Código de territorio..."
57+
58+
#. module: partner_code_program_territory
59+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__company_id
60+
msgid "Company"
61+
msgstr "Compañia"
62+
63+
#. module: partner_code_program_territory
64+
#: model:ir.model,name:partner_code_program_territory.model_res_partner
65+
msgid "Contact"
66+
msgstr "Contacto"
67+
68+
#. module: partner_code_program_territory
69+
#. odoo-python
70+
#: code:addons/partner_code_program_territory/models/res_partner_code_program_territory.py:0
71+
#: model_terms:ir.ui.view,arch_db:partner_code_program_territory.res_partner_code_program_form_view
72+
#: model_terms:ir.ui.view,arch_db:partner_code_program_territory.res_partner_code_program_territory_form_view
73+
#, python-format
74+
msgid "Contacts"
75+
msgstr "Contactos"
76+
77+
#. module: partner_code_program_territory
78+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__create_uid
79+
msgid "Created by"
80+
msgstr ""
81+
82+
#. module: partner_code_program_territory
83+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__create_date
84+
msgid "Created on"
85+
msgstr ""
86+
87+
#. module: partner_code_program_territory
88+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__display_name
89+
msgid "Display Name"
90+
msgstr ""
91+
92+
#. module: partner_code_program_territory
93+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__id
94+
msgid "ID"
95+
msgstr ""
96+
97+
#. module: partner_code_program_territory
98+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__write_uid
99+
msgid "Last Updated by"
100+
msgstr ""
101+
102+
#. module: partner_code_program_territory
103+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__write_date
104+
msgid "Last Updated on"
105+
msgstr ""
106+
107+
#. module: partner_code_program_territory
108+
#: model:ir.model,name:partner_code_program_territory.model_res_partner_code_program_territory_mixin
109+
msgid ""
110+
"Mixin model for applying to any object that wants to have a code program "
111+
"territory"
112+
msgstr ""
113+
"Modelo mixin para aplicar a cualquier objeto que quiera tener un código de "
114+
"territorio"
115+
116+
#. module: partner_code_program_territory
117+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__name
118+
msgid "Name"
119+
msgstr "Nombre\t\t\t"
120+
121+
#. module: partner_code_program_territory
122+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program__code_terriroty_count
123+
#: model:ir.model.fields,field_description:partner_code_program_territory.field_res_partner_code_program_territory__res_partner_count
124+
msgid "Number of Contacts"
125+
msgstr "Número de contactos"
126+
127+
#. module: partner_code_program_territory
128+
#: model:ir.actions.act_window,name:partner_code_program_territory.res_partner_code_program_territory_action
129+
#: model:ir.ui.menu,name:partner_code_program_territory.menu_res_partner_code_program_territory
130+
msgid "Program Territory Codes"
131+
msgstr "Códigos de territorio"
132+
133+
#. module: partner_code_program_territory
134+
#: model:ir.model.constraint,message:partner_code_program_territory.constraint_res_partner_code_program_territory_code_uniq
135+
msgid ""
136+
"You already have a code program territory with that code. The code must be "
137+
"unique. "
138+
msgstr ""
139+
"Ya tiene un código de territorio con ese código. El código debe ser único. "
140+
141+
#. module: partner_code_program_territory
142+
#: model:ir.model.constraint,message:partner_code_program_territory.constraint_res_partner_code_program_territory_name_uniq
143+
msgid ""
144+
"You already have a code program territory with that name. The name must be "
145+
"unique. "
146+
msgstr ""
147+
"Ya tiene un código de territorio con ese nombre. El nombre debe ser único. "
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from . import res_partner_code_program_territory_mixin
4+
from . import res_partner_code_program_territory
5+
from . import res_partner_code_program
6+
from . import res_partner
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2024 Alberto Martínez <alberto.martinez@sygel.es>
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import api, fields, models
5+
6+
7+
class ResPartner(models.Model):
8+
_inherit = "res.partner"
9+
10+
code_program_territory_id = fields.Many2one(
11+
string="Code Program Territory",
12+
comodel_name="res.partner.code.program.territory",
13+
ondelete="restrict",
14+
domain="['|', ('code_program_id', '=?', code_program_id), \
15+
('code_program_id', '=', False)]",
16+
)
17+
code_program_territory_name = fields.Char(
18+
string="Code Program Territory Name",
19+
related="code_program_territory_id.name",
20+
)
21+
22+
@api.onchange("code_program_id")
23+
def _onchange_code_program_id(self):
24+
if (
25+
self.code_program_id
26+
and self.code_program_id != self.code_program_territory_id.code_program_id
27+
and self.code_program_territory_id.code_program_id
28+
):
29+
self.code_program_territory_id = False
30+
31+
@api.onchange("code_program_territory_id")
32+
def _onchange_code_program_territory_id(self):
33+
if (
34+
self.code_program_territory_id.code_program_id
35+
and self.code_program_id != self.code_program_territory_id.code_program_id
36+
):
37+
self.code_program_id = self.code_program_territory_id.code_program_id
38+
39+
@api.model
40+
def _address_fields(self):
41+
return super()._address_fields() + [
42+
"code_program_territory_id",
43+
"code_program_territory_name",
44+
]
45+
46+
@api.model
47+
def _commercial_fields(self):
48+
return super()._commercial_fields() + ["code_program_territory_id"]

0 commit comments

Comments
 (0)