Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] connector_ecommerce #75

Merged
merged 77 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
ca30a6b
[CHG] rename 'base_sale_multichannels' to 'connector_ecommerce'
guewen Feb 19, 2013
fa30301
[ADD] Base support to export picking (partial and complete)
jgrandguillaume Mar 12, 2013
2be8130
[FIX] improve styling, remove unused imports, fix license (done by Joel)
guewen Mar 12, 2013
cfe1333
[ADD] Event to handle the adding of the tracking number on picking
jgrandguillaume Mar 13, 2013
205ee22
[FIX] remove the carrier tracking number from the event, fix missing …
guewen Mar 13, 2013
f664928
[ADD] Support for exporting the account_invoice to Magento
jgrandguillaume Mar 13, 2013
b4bf8f8
[FIX] styling, license, imports, some fixes
guewen Mar 13, 2013
ae6237a
[FIX] add product_view.xml file
bealdav Mar 14, 2013
d655a80
[IMP] start adding support of onchange in connector-ecommerce
sebastienbeau Mar 13, 2013
bd8d6fd
[REF] code review
Mar 14, 2013
bbeaa23
[IMP] code review
sebastienbeau Mar 14, 2013
a7c40fb
[IMP] play on change on sale.order and sale.order.lines in new framew…
gurneyalex Mar 15, 2013
6d46e67
[FIX] wrong arguments in action_done
guewen Mar 18, 2013
4c1619a
[ADD] 'Authorized' import rules to be able to import sales orders aut…
Jun 14, 2013
e9ce90b
[REF] started to use ConnectorUnit classes to add extra lines in sale…
guewen Jun 25, 2013
abdd216
Fix a bug : remove special fields before database storage (avoid to t…
Jun 27, 2013
5041655
[DEL] remove old stuff
guewen Jul 5, 2013
98c0a1c
[IMP] - make possible to inherit the method _add_order_extra_line (do…
mathieuvatel Jul 15, 2013
7f559fa
[FIX] indentation according to pep8
guewen Jul 15, 2013
a60654f
Added "invoice validated" event and called upon "on_invoice_validate".
Aug 5, 2013
81c2925
[FIX] the onchange test had a TypeError, now it fails for some reason
guewen Aug 5, 2013
ff5d8d8
[BUMP] release 2.1.0
guewen Jan 15, 2014
68f4e4e
[IMP] move product_normal_form_view in connector_base_product
bealdav Feb 4, 2014
f47d0a1
[FIX] product_view.xml in __openerp__.py
bealdav Feb 14, 2014
716299e
The special sales orders lines can have a sequence and have low prior…
guewen Mar 31, 2014
7b915bf
[FIX] related_backorder_ids shoud not be linked with a new copy
rdeheele Apr 7, 2014
34c0e80
rise the sequence of the special lines to reduce chances to be reache…
guewen Apr 9, 2014
8401bea
[IMP] allow to override payment rules
bealdav Apr 25, 2014
1c89404
Bump to version 2.2.0
guewen May 26, 2014
a1fa27e
set modules to not installable
guewen Jul 7, 2014
2e5b67c
Add bug tracker link on README.rst
yvaucher May 22, 2015
fcad44f
Trigger the change of price on the newly created product
guewen Jul 23, 2015
d6515e0
[FIX] Bug throwing exception importing sale order
kikopeiro Aug 27, 2015
9f085d9
[UPD] prefix versions with 8.0
sbidoul Oct 9, 2015
17562b0
[MIG] Make modules uninstallable
pedrobaeza Oct 14, 2015
9721b5a
[IMP] made module installable
parthiv Mar 18, 2016
ee8634d
Replace product.price.type by predefined fields
guewen Apr 12, 2016
ff1609b
[FIX] changed to MVC structure
atchuthan May 12, 2016
a913e6e
Remove account.tax.group, now exists in 'account'
guewen May 26, 2016
2341696
[FIX] renamed filename to account_payment_mode
atchuthan May 27, 2016
f6c153d
Capitalize products names for consistency
guewen May 27, 2016
1a126b1
[FIX] removed duplicate line
parthiv Aug 24, 2016
077513d
Extract onchange fields for better extensibility
guewen Sep 8, 2016
c16d19b
[MIG] Make modules uninstallable
pedrobaeza Oct 6, 2016
3c224d1
connector_ecommerce: Add security groups to avoid show information al…
sergio-teruel Jan 20, 2017
f50222e
[MIG] Migration to 10.0
Nov 23, 2016
f06cc9e
[MIG] Migration to 10.0: Adapt code to 10.0
lmignon May 15, 2017
c865d07
fix message_post() expecting a len(recordset) == 1
guewen Jun 9, 2017
5ec684d
Fire new event: 'on_picking_dropship_done' when an 'incoming' shipmen…
jaredkipe Oct 21, 2017
efcc1c5
Fix lint error introduced in #43
guewen Oct 30, 2017
f26c7e9
[MIG] connector_ecommerce to V11
hugosantosred Feb 8, 2018
c167d54
Connector Ecommerce to version 12
ljimenezsidoo Mar 20, 2019
347ad53
Update connector_ecommerce/views/sale_view.xml
sebalix Apr 29, 2019
afd3d82
Update connector_ecommerce/tests/test_picking_event.py
ljimenezsidoo May 31, 2019
1a5b44c
Update connector_ecommerce/tests/test_picking_event.py
ljimenezsidoo May 31, 2019
35544aa
RMV rule_group from ecommerce data xml
Oct 15, 2019
562b2aa
[IMP] connector_ecommerce: black, isort
HviorForgeFlow Mar 23, 2020
52fe5b8
[MIG] connector_ecommerce: Migration to 13.0
HviorForgeFlow Mar 23, 2020
faa23fa
[FIX]not exist field in model raise error so remove those before call…
bizzappdev Nov 23, 2020
eba7c19
[FIX]proper exception rule
bizzappdev Feb 4, 2021
195e53f
[FIX]tax_id test case from plan onchange. (based on Company from orde…
bizzappdev Mar 8, 2021
57f5b93
[FIX]pre-commit
bizzappdev Mar 8, 2021
f435e54
[FIX]remove not needed fields
bizzappdev Mar 9, 2021
22911a7
[FIX] Fix action done
florian-dacosta Jan 3, 2021
c8fd806
[FIX] Fix Invoice validate notification
florian-dacosta Jan 14, 2021
a256d91
[FIX] Remove checkpoint as it has been removed from connector
florian-dacosta Apr 2, 2021
22e3d5c
[IMP] connector_ecommerce: black, isort, prettier
hailangvn May 16, 2021
2bd7516
[MIG] connector_ecommerce: Migration to 14.0
hailangvn May 16, 2021
98a54b4
[FIX] rule must be created as inactive as it could break standard beh…
Aug 19, 2021
dff8436
[FIX] connector_ecommerce: resolve error searching non-stored field
hailangvn Feb 24, 2022
88252e4
[IMP] update dotfiles [ci skip]
OCA-git-bot Mar 30, 2022
a94bcc7
[FIX] connector_ecommerce: remove obsoleted rule
hailangvn Apr 25, 2022
f415362
Missing env variable in openupgrade method call
StephaneMangin May 4, 2022
24759e2
[MIG][15.0] connector_ecommerce: 15.0
flachica May 6, 2022
6c442ec
[MIG] connector_ecommerce: Migration to 16.0
juliocabrerizo Oct 4, 2022
6296375
[MIG] connector_ecommerce: FIX test
asierneiradev Jan 31, 2023
6cfac49
[16.0][MIG] connector_ecommerce: adapt necessary changes for correct …
asierneiradev Mar 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions connector_ecommerce/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License

Connector for E-Commerce
========================

This modules aims to be a common layer for the connectors dealing with
e-commerce.

It sits on top of the `connector`_ framework and is used by the
e-commerce connectors, like `magentoerpconnect`_ or
`prestashoperpconnect`_.

That's a technical module, which include amongst other things:

Events

On which the connectors can subscribe listeners.
The events it adds are:

* ``on_invoice_paid(self, record)``
* ``on_invoice_validated(self, record)``
* ``on_invoice_validated(self, record)``
* ``on_picking_out_done(self, record, method)`` where method is
'partial' or 'complete'
* ``on_tracking_number_added(self, record)``
* ``on_product_price_changed(self, record)``

Components

A piece of code which allows to play all the ``onchanges`` required
when we create a sales order.

Another one which allows to add special lines in imported sales orders
such as Shipping fees, Cash on Delivery or Discounts.

Data Model

Add structures shared for e-commerce connectors

.. _`connector`: http://odoo-connector.com
.. _`magentoerpconnect`: http://odoo-magento-connector.com
.. _`prestashoperpconnect`: https://github.com/OCA/connector-prestashop

Installation
============

This module is a dependency for more advanced connectors. It does
nothing on its own and there is no reason to install it alone.


Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-ecommerce/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/connector-ecommerce/issues/new?body=module:%20connector_ecommerce%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.


Credits
=======

Contributors
------------

See `contributors' list`_

.. _contributors' list: ./AUTHORS

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization
whose mission is to support the collaborative development of Odoo
features and promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
3 changes: 3 additions & 0 deletions connector_ecommerce/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import components
from . import models
from . import wizard
30 changes: 30 additions & 0 deletions connector_ecommerce/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# © 2013-2016 Camptocamp SA
# © 2013-2016 Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

{
"name": "Connector for E-Commerce",
"version": "16.0.1.0.0",
"category": "Hidden",
"author": "Camptocamp,Akretion,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/connector-ecommerce",
"license": "AGPL-3",
"depends": [
"connector",
"sale_automatic_workflow_payment_mode",
"sale_exception",
"delivery",
"connector_base_product",
],
"data": [
"security/security.xml",
"security/ir.model.access.csv",
"wizard/sale_ignore_cancel_view.xml",
"data/ecommerce_data.xml",
"views/sale_view.xml",
"views/invoice_view.xml",
"views/stock_view.xml",
"views/payment_mode_view.xml",
],
"installable": True,
}
2 changes: 2 additions & 0 deletions connector_ecommerce/components/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import line_builder
from . import sale_order_onchange
110 changes: 110 additions & 0 deletions connector_ecommerce/components/line_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# © 2013-2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import models

from odoo.addons.component.core import Component


class SpecialOrderLineBuilder(Component):
"""Base class to build a sales order line for a sales order

Used when extra order lines have to be added in a sales order
but we only know some parameters (product, price, ...), for instance,
a line for the shipping costs or the gift coupons.

It can be subclassed to customize the way the lines are created.

Usage::

builder = self.components(usage='shipping.line.builder',
model_name='sale.order.line')
builder.price_unit = 100
builder.get_line()

"""

_name = "ecommerce.order.line.builder"
_inherit = "base.connector"
_usage = "order.line.builder"

def __init__(self, work_context):
super().__init__(work_context)
self.product = None # id or browse_record
# when no product_id, fallback to a product_ref
self.product_ref = None # tuple (module, xmlid)
self.price_unit = None
self.quantity = 1
self.sign = 1
self.sequence = 980

def get_line(self):
assert self.product_ref or self.product
assert self.price_unit is not None

product = self.product
if product is None:
product = self.env.ref(".".join(self.product_ref))

if not isinstance(product, models.BaseModel):
product = self.env["product.product"].browse(product)
return {
"product_id": product.id,
"name": product.name,
"product_uom": product.uom_id.id,
"product_uom_qty": self.quantity,
"price_unit": self.price_unit * self.sign,
"sequence": self.sequence,
}


class ShippingLineBuilder(Component):
"""Return values for a Shipping line"""

_name = "ecommerce.order.line.builder.shipping"
_inherit = "ecommerce.order.line.builder"
_usage = "order.line.builder.shipping"

def __init__(self, work_context):
super().__init__(work_context)
self.product_ref = ("connector_ecommerce", "product_product_shipping")
self.sequence = 999

def get_line(self):
values = super().get_line()
values["is_delivery"] = True
return values


class CashOnDeliveryLineBuilder(Component):
"""Return values for a Cash on Delivery line"""

_name = "ecommerce.order.line.builder.cod"
_inherit = "ecommerce.order.line.builder"
_usage = "order.line.builder.cod"

def __init__(self, work_context):
super().__init__(work_context)
self.product_ref = ("connector_ecommerce", "product_product_cash_on_delivery")
self.sequence = 995


class GiftOrderLineBuilder(Component):
"""Return values for a Gift line"""

_name = "ecommerce.order.line.builder.gift"
_inherit = "ecommerce.order.line.builder"
_usage = "order.line.builder.gift"

def __init__(self, work_context):
super().__init__(work_context)
self.product_ref = ("connector_ecommerce", "product_product_gift")
self.sign = -1
self.gift_code = None
self.sequence = 990

def get_line(self):
line = super().get_line()
if self.gift_code:
line["name"] = "{} [{}]".format(line["name"], self.gift_code)
return line
112 changes: 112 additions & 0 deletions connector_ecommerce/components/sale_order_onchange.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# © 2013-TODAY Akretion (Sébastien Beau)
# © 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo.addons.component.core import Component


class OnChangeManager(Component):
_name = "ecommerce.onchange.manager"
_inherit = "base.connector"

def get_new_values(self, record, on_change_result, model=None):
vals = on_change_result.get("value", {})
new_values = {}
for fieldname, value in vals.items():
if fieldname not in record:
if model:
column = self.env[model]._fields[fieldname]
if column.type == "many2one":
value = value[0] # many2one are tuple (id, name)
new_values[fieldname] = value
return new_values

def play_onchanges(self, model, values, onchange_fields):
model = self.env[model]
onchange_specs = model._onchange_spec()

# we need all fields in the dict even the empty ones
# otherwise 'onchange()' will not apply changes to them
all_values = {k: v for k, v in values.items() if k in model._fields}
not_values = {k: v for k, v in values.items() if k not in model._fields}
for field in model._fields:
if field not in all_values:
all_values[field] = False

# we work on a temporary record
new_record = model.new(all_values)

new_values = {}
for field in onchange_fields:
onchange_values = new_record.onchange(all_values, field, onchange_specs)
new_values.update(
self.get_new_values(values, onchange_values, model=model._name)
)
all_values.update(new_values)

for fld in not_values:
if fld not in all_values:
all_values[fld] = not_values[fld]
res = {f: v for f, v in all_values.items() if f in values or f in new_values}
return res


class SaleOrderOnChange(Component):
_name = "ecommerce.onchange.manager.sale.order"
_inherit = "ecommerce.onchange.manager"
_usage = "ecommerce.onchange.manager.sale.order"

order_onchange_fields = ["partner_id"]

line_onchange_fields = ["order_id", "product_id"]

def play(self, order, order_lines):
"""Play the onchange of the sales order and it's lines

:param order: sales order values
:type: dict
:param order_lines: data of the sales order lines
:type: list of dict

:return: the sales order updated by the onchanges
:rtype: dict
"""
# play onchange on sales order
order = self.play_onchanges("sale.order", order, self.order_onchange_fields)

# play onchange on sales order line
processed_order_lines = []
line_lists = [order_lines]
if "order_line" in order and order["order_line"] is not order_lines:
# we have both backend-dependent and oerp-native order lines.
# oerp-native lines can have been added to map
# shipping fees with an Odoo Product
line_lists.append(order["order_line"])

for line_list in line_lists:
for idx, command_line in enumerate(line_list):
# line_list format:[(0, 0, {...}), (0, 0, {...})]
if command_line[0] in (0, 1): # create or update values
# we work on a temporary record
order_model = self.env["sale.order"]

all_values = {
k: v for k, v in order.items() if k in order_model._fields
}
for field in order_model._fields:
if field not in all_values:
all_values[field] = False
new_record = order_model.new(all_values)
# keeps command number and ID (or 0)
old_line_data = command_line[2]
# passing order_id also so order_id.company_id based onchange will
# also work
old_line_data["order_id"] = new_record
new_line_data = self.play_onchanges(
"sale.order.line", old_line_data, self.line_onchange_fields
)
new_line = (command_line[0], command_line[1], new_line_data)
processed_order_lines.append(new_line)
# in place modification of the sales order line in the list
line_list[idx] = new_line
return order
Loading