Skip to content

Commit

Permalink
Port laposte to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
hparfr committed Dec 13, 2017
1 parent d2fb37e commit 91063f9
Show file tree
Hide file tree
Showing 23 changed files with 83 additions and 208 deletions.
2 changes: 2 additions & 0 deletions delivery_roulier/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import models

from .decorator import implemented_by_carrier
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Delivery Carrier Roulier',
'version': '9.0.0.0.0',
'version': '10.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)',
'summary': 'Integration of multiple carriers',
'maintainer': 'Akretion, Odoo Community Association (OCA)',
Expand Down
41 changes: 41 additions & 0 deletions delivery_roulier/decorator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# coding: utf-8
# @author Raphael Reverdy <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from functools import wraps


def implemented_by_carrier(func):
"""Decorator: call _carrier_prefixed method instead.
Usage:
@implemented_by_carrier
def _do_something()
def _laposte_do_something()
def _gls_do_something()
At runtime, picking._do_something() will try to call
the carrier spectific method or fallback to generic _do_something
"""
@wraps(func)
def wrapper(cls, *args, **kwargs):
fun_name = func.__name__

def get_carrier_type(cls, *args, **kwargs):
if hasattr(cls, 'carrier_type'):
return cls.carrier_type
pickings = [
obj for obj in args
if getattr(obj, '_name', '') == 'stock.picking']
if len(pickings) > 0:
return pickings[0].carrier_type
if cls[0].carrier_id:
return cls[0].carrier_id.carrier_type

carrier_type = get_carrier_type(cls, *args, **kwargs)
fun = '_%s%s' % (carrier_type, fun_name)
if not hasattr(cls, fun):
fun = '_roulier%s' % (fun_name)
return getattr(cls, fun)(*args, **kwargs)
return wrapper
32 changes: 5 additions & 27 deletions delivery_roulier/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import datetime, timedelta
from functools import wraps
import logging

from openerp import models, fields, api
from openerp.tools.translate import _
from openerp.exceptions import Warning as UserError
from odoo import models, fields, api
from odoo.tools.translate import _
from odoo.exceptions import UserError

from ..decorator import implemented_by_carrier

_logger = logging.getLogger(__name__)
try:
Expand All @@ -18,29 +19,6 @@
_logger.debug('Cannot `import roulier`.')


def implemented_by_carrier(func):
"""Decorator: call _carrier_prefixed method instead.
Usage:
@implemented_by_carrier
def _do_something()
def _laposte_do_something()
def _gls_do_something()
At runtime, picking._do_something() will try to call
the carrier spectific method or fallback to generic _do_something
"""
@wraps(func)
def wrapper(cls, *args, **kwargs):
fun_name = func.__name__
fun = '_%s%s' % (cls.carrier_type, fun_name)
if not hasattr(cls, fun):
fun = '_roulier%s' % (fun_name)
# return func(cls, *args, **kwargs)
return getattr(cls, fun)(*args, **kwargs)
return wrapper


class StockPicking(models.Model):
_inherit = 'stock.picking'

Expand Down
47 changes: 5 additions & 42 deletions delivery_roulier/models/stock_quant_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
# David BEAL <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from functools import wraps
import logging
import base64

from openerp import models, api, fields
from openerp.tools.translate import _
from openerp.exceptions import UserError
from odoo import models, api, fields
from odoo.tools.translate import _
from odoo.exceptions import UserError

from ..decorator import implemented_by_carrier

_logger = logging.getLogger(__name__)
try:
Expand All @@ -22,44 +23,6 @@
_logger.debug('Cannot `import roulier`.')


def implemented_by_carrier(func):
"""Decorator: call _carrier_prefixed method instead.
Usage:
@implemented_by_carrier
def _do_something()
def _laposte_do_something()
def _gls_do_something()
At runtime, picking._do_something() will try to call
the carrier spectific method or fallback to generic _do_something
"""
@wraps(func)
def wrapper(cls, *args, **kwargs):
fun_name = func.__name__

def get_carrier_type(cls, *args, **kwargs):
if hasattr(cls, 'carrier_type'):
return cls.carrier_type
# TODO: est-ce bien utile si on carrier_id ?
pickings = [
obj for obj in args
if getattr(obj, '_name', '') == 'stock.picking']
if len(pickings) > 0:
return pickings[0].carrier_type
if cls[0].carrier_id:
return cls[0].carrier_id.carrier_type

carrier_type = get_carrier_type(cls, *args, **kwargs)
fun = '_%s%s' % (carrier_type, fun_name)
if not hasattr(cls, fun):
fun = '_roulier%s' % (fun_name)
# return func(cls, *args, **kwargs)
return getattr(cls, fun)(*args, **kwargs)
return wrapper


class StockQuantPackage(models.Model):
_inherit = 'stock.quant.package'

Expand Down
7 changes: 2 additions & 5 deletions delivery_roulier/views/stock_quant_package.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<!-- add Tracking button -->
<record id="view_quant_package_form" model="ir.ui.view">
<field name="model">stock.quant.package</field>
Expand All @@ -12,6 +11,4 @@
</div>
</field>
</record>

</data>
</openerp>
</odoo>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# coding: utf-8
# © 2016 Raphael REVERDY <[email protected]>
# © 2017 Raphael REVERDY <[email protected]>
# David BEAL <[email protected]>
# Sébastien BEAU <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': 'Delivery Carrier La Poste (fr)',
'version': '9.0.1.0.0',
'version': '10.0.1.0.0',
'author': 'Akretion',
'summary': 'Generate Label for La Poste/Colissimo',
'maintainer': 'Akretion,Odoo Community Association (OCA)',
Expand All @@ -19,6 +18,7 @@
'website': 'http://www.akretion.com/',
'data': [
'data/delivery.xml',
'data/keychain.xml',
'views/stock_picking.xml',
],
'external_dependencies': {
Expand Down
9 changes: 3 additions & 6 deletions delivery_roulier_laposte/data/delivery.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<!-- <data noupdate="1">-->
<data>
<odoo>
<data noupdate="1">

<!-- PARTNER -->
<record id="partner_la_poste" model="res.partner">
Expand All @@ -22,7 +21,6 @@

<!-- DELIVERY CARRIER -->
<record id="delivery_carrier_DOM" model="delivery.carrier">
<field name="name">Colissimo Domicile</field>
<field name="name">Colissimo Domicile (FR + Europe)</field>
<field name="default_code">DOM</field>
<field name="code">DOM</field>
Expand Down Expand Up @@ -253,6 +251,5 @@
<!-- Pas de niveau de recommandation possible: seulement assurance -->
</record>


</data>
</openerp>
</odoo>
7 changes: 2 additions & 5 deletions delivery_roulier_laposte/data/keychain.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<!--<data noupdate="1">-->
<data>
<odoo>
<record id="keychain_la_poste" model="keychain.account">
<field name="name">La Poste default</field>
<field name="namespace">roulier_laposte</field>
<field name="technical_name">laposte_default_account</field>
</record>
</data>
</openerp>
</odoo>
1 change: 0 additions & 1 deletion delivery_roulier_laposte/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from . import company
from . import stock_picking
from . import delivery
from . import stock_quant_package
Expand Down
39 changes: 0 additions & 39 deletions delivery_roulier_laposte/models/company.py

This file was deleted.

7 changes: 2 additions & 5 deletions delivery_roulier_laposte/models/keychain.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ class AccountProduct(models.Model):
selection_add=[(LAPOSTE_KEYCHAIN_NAMESPACE, 'Laposte')])

def _roulier_laposte_init_data(self):
return {
"codeAgence": "",
}
return {}

def _roulier_laposte_validate_data(self, data):
# on aurait pu utiliser Cerberus ici
return 'codeAgence' in data
return True
10 changes: 4 additions & 6 deletions delivery_roulier_laposte/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
# David BEAL <[email protected]>
# Sébastien BEAU
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from openerp import models, fields, api
from openerp.exceptions import Warning as UserError
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT

from datetime import datetime, timedelta

from odoo import models, fields, api
from odoo.exceptions import UserError
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -107,7 +105,7 @@ def _laposte_convert_address(self, partner):
"""
address = self._roulier_convert_address(partner) or {}
# get_split_adress from partner_helper module
streets = partner._get_split_address(partner, 3, 38)
streets = partner._get_split_address(3, 38)
address['street'], address['street2'], address['street3'] = streets
# TODO manage in a better way if partner_firstname is installed
address['firstName'] = '.'
Expand Down
2 changes: 1 addition & 1 deletion delivery_roulier_laposte/models/stock_quant_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# David BEAL <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import _, api, models
import logging
from odoo import _, api, models

_logger = logging.getLogger(__name__)
try:
Expand Down
6 changes: 2 additions & 4 deletions delivery_roulier_laposte/views/stock_picking.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<openerp>
<data>
<odoo>
<record id="view_picking_withcarrier_out_form" model="ir.ui.view">
<field name="model">stock.picking</field>
<field name="inherit_id"
Expand All @@ -27,5 +26,4 @@
<!-- 'readonly': [('state','=','done')], -->
</field>
</record>
</data>
</openerp>
</odoo>
5 changes: 2 additions & 3 deletions delivery_roulier_option/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

{
'name': 'Delivery Roulier Option',
'version': '9.0.1.0.0',
'author': 'Akretion, Odoo Community Association (OCA)',
'version': '10.0.1.0.0',
'author': 'Akretion',
'summary': 'Add options to roulier modules',
'maintainer': 'Akretion, Odoo Community Association (OCA)',
'category': 'Warehouse',
Expand All @@ -18,7 +18,6 @@
'data': [
'data/delivery.xml',
],
'demo': [],
'installable': True,
'license': 'AGPL-3',
}
8 changes: 3 additions & 5 deletions delivery_roulier_option/data/delivery.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<odoo>
<data noupdate="1">
<!-- DELIVERY CARRIER TEMPLATE OPTION -->
<record id="carrier_opt_tmpl_ACK" model="delivery.carrier.template.option">
<field name="name">Acknowledgment</field>
Expand All @@ -22,6 +21,5 @@
<field name="name">Insurance</field>
<field name="code">INS</field>
</record>

</data>
</openerp>
</odoo>
Loading

0 comments on commit 91063f9

Please sign in to comment.