Browse Source

Add module partner_tz

14.0
Akim Juillerat 5 years ago
committed by Dũng (Trần Đình)
parent
commit
b34399434b
  1. 2
      partner_tz/__init__.py
  2. 16
      partner_tz/__manifest__.py
  3. 1
      partner_tz/models/__init__.py
  4. 10
      partner_tz/models/res_partner.py
  5. 1
      partner_tz/readme/CONTRIBUTORS.rst
  6. 3
      partner_tz/readme/DESCRIPTION.rst
  7. 1
      partner_tz/tools/__init__.py
  8. 58
      partner_tz/tools/tz_utils.py
  9. 13
      partner_tz/views/res_partner.xml

2
partner_tz/__init__.py

@ -0,0 +1,2 @@
from . import models
from . import tools

16
partner_tz/__manifest__.py

@ -0,0 +1,16 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
{
"name": "Partner timezone",
"summary": "Remove partner timezone default value and display on form",
"version": "13.0.1.0.0",
"development_status": "Alpha",
"category": "Uncategorized",
"website": "https://github.com/OCA/partner-contact",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["base"],
"data": ["views/res_partner.xml"],
}

1
partner_tz/models/__init__.py

@ -0,0 +1 @@
from . import res_partner

10
partner_tz/models/res_partner.py

@ -0,0 +1,10 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
tz = fields.Selection(default=None)

1
partner_tz/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Akim Juillerat <akim.juillerat@camptocamp.com>

3
partner_tz/readme/DESCRIPTION.rst

@ -0,0 +1,3 @@
This module removes timezone default value on res.partner and display the field
on form view.
Moreover it provides a few tools function in `tools/tz_utils.py`.

1
partner_tz/tools/__init__.py

@ -0,0 +1 @@
from .tz_utils import *

58
partner_tz/tools/tz_utils.py

@ -0,0 +1,58 @@
# Copyright 2020 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
import pytz
from datetime import datetime, date
UTC_TZ = pytz.timezone('UTC')
def tz_to_tz_naive_datetime(from_tz, to_tz, date_time):
"""
Convert tz-naive datetime from a specifc tz to a tz-naive datetime of a specific tz
:param from_tz: pytz.timezone object or tz selection value
:param to_tz: pytz.timezone object or tz selection value
:param date_time: tz-naive datetime.datetime object
:return: tz-naive datetime.datetime object
"""
if isinstance(from_tz, str):
from_tz = pytz.timezone(from_tz)
if isinstance(to_tz, str):
to_tz = pytz.timezone(to_tz)
return from_tz.localize(date_time).astimezone(to_tz).replace(tzinfo=None)
def tz_to_utc_naive_datetime(from_tz, date_time):
return tz_to_tz_naive_datetime(from_tz, UTC_TZ, date_time)
def utc_to_tz_naive_datetime(to_tz, date_time):
return tz_to_tz_naive_datetime(UTC_TZ, to_tz, date_time)
def tz_to_tz_time(from_tz, to_tz, time, base_date=None):
"""
Convert datetime.time from a specific tz to a datetime.time of a specific tz
:param from_tz: pytz.timezone object or tz selection value
:param to_tz: pytz.timezone object or tz selection value
:param time: datetime.time object
:param base_date: OPTIONAL datetime.date or datetime.datetime object to use
for the conversion
:return: datetime.time object
"""
# Combine time with a date
if base_date is None:
base_date = date.today()
date_time = datetime.combine(base_date, time)
new_date_time = tz_to_tz_naive_datetime(from_tz, to_tz, date_time)
return new_date_time.time()
def tz_to_utc_time(from_tz, time, base_date=None):
return tz_to_tz_time(from_tz, UTC_TZ, time, base_date=base_date)
def utc_to_tz_time(to_tz, time, base_date=None):
return tz_to_tz_time(UTC_TZ, to_tz, time, base_date=base_date)

13
partner_tz/views/res_partner.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_partner_form_inherit" model="ir.ui.view">
<field name="name">res.partner.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<field name="vat" position="before">
<field name="tz" />
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save