Skip to content

Commit

Permalink
Listen for new on_picking_dropship_done event.
Browse files Browse the repository at this point in the history
Add Rewards and StoreCredit payment methods.

(Travis Bump)
  • Loading branch information
jaredkipe authored and hugosantosred committed Mar 6, 2018
1 parent 2980ffa commit 8145a35
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions connector_magento/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from . import exporter
from . import mapper
from . import deleter
from . import line_builder
41 changes: 41 additions & 0 deletions connector_magento/components/line_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
# © 2017 Hibou Corp.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

"""
Line Builders for Magento psudo-payment methods (Store Credit, Rewards...).
"""

from odoo.addons.component.core import Component


class StoreCreditLineBuilder(Component):
""" Return values for a Store Credit line """

_name = 'magento.order.line.builder.store_credit'
_inherit = 'ecommerce.order.line.builder'
_usage = 'order.line.builder.magento.store_credit'

def __init__(self, work_context):
super(StoreCreditLineBuilder, self).__init__(work_context)
self.product_ref = ('connector_magento',
'product_product_store_credit')
self.sign = -1
self.sequence = 991


class RewardsLineBuilder(Component):
""" Return values for a Rewards line """

_name = 'magento.order.line.builder.rewards'
_inherit = 'ecommerce.order.line.builder'
_usage = 'order.line.builder.magento.rewards'

def __init__(self, work_context):
super(RewardsLineBuilder, self).__init__(work_context)
self.product_ref = ('connector_magento',
'product_product_rewards')
self.sign = -1
self.sequence = 992
18 changes: 18 additions & 0 deletions connector_magento/data/connector_magento_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,23 @@ if sale.magento_bind_ids and abs(sale.amount_tax - sale.magento_bind_ids[0].tota
<field name="active" eval="True"/>
</record>

<record id="product_product_store_credit" model="product.product">
<field name="default_code">MAGENTO STORE CREDIT</field>
<field name="list_price">0.0</field>
<field name="standard_price">0.0</field>
<field name="type">service</field>
<field name="name">Magento Store Credit</field>
<field name="categ_id" ref="connector_ecommerce.product_categ_services" />
</record>

<record id="product_product_rewards" model="product.product">
<field name="default_code">MAGENTO REWARDS</field>
<field name="list_price">0.0</field>
<field name="standard_price">0.0</field>
<field name="type">service</field>
<field name="name">Magento Rewards</field>
<field name="categ_id" ref="connector_ecommerce.product_categ_services" />
</record>

</data>
</odoo>
28 changes: 28 additions & 0 deletions connector_magento/models/sale_order/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,40 @@ def _add_gift_cards_line(self, map_record, values):
values['order_line'].append(line)
return values

def _add_store_credit_line(self, map_record, values):
record = map_record.source
if not record.get('customer_balance_amount'):
return values
amount = float(record['customer_balance_amount'])
if amount == 0.0:
return values
line_builder = self.component(usage='order.line.builder.magento.store_credit')
line_builder.price_unit = amount
line = (0, 0, line_builder.get_line())
values['order_line'].append(line)
return values

def _add_rewards_line(self, map_record, values):
record = map_record.source
if not record.get('reward_currency_amount'):
return values
amount = float(record['reward_currency_amount'])
if amount == 0.0:
return values
line_builder = self.component(usage='order.line.builder.magento.rewards')
line_builder.price_unit = amount
line = (0, 0, line_builder.get_line())
values['order_line'].append(line)
return values

def finalize(self, map_record, values):
values.setdefault('order_line', [])
values = self._add_shipping_line(map_record, values)
values = self._add_cash_on_delivery_line(map_record, values)
values = self._add_gift_certificate_line(map_record, values)
values = self._add_gift_cards_line(map_record, values)
values = self._add_store_credit_line(map_record, values)
values = self._add_rewards_line(map_record, values)
values.update({
'partner_id': self.options.partner_id,
'partner_invoice_id': self.options.partner_invoice_id,
Expand Down
3 changes: 3 additions & 0 deletions connector_magento/models/stock_picking/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ def on_tracking_number_added(self, record):
# executed after the picking creation
binding.with_delay(priority=20).export_tracking_number()

def on_picking_dropship_done(self, record, picking_method):
return self.on_picking_out_done(record, picking_method)

def on_picking_out_done(self, record, picking_method):
"""
Create a ``magento.stock.picking`` record. This record will then
Expand Down

0 comments on commit 8145a35

Please sign in to comment.