forked from mollie/mollie-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mollie#102 from mollie/14.0-shipment-api
[ADD/IMP] added module for shipment sync + other improvements
- Loading branch information
Showing
18 changed files
with
254 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
{ | ||
'name': 'Mollie Shipment Sync', | ||
'version': '14.0.0.0', | ||
'description': '', | ||
'summary': 'Sync shipment details to mollie payments', | ||
'author': 'Mollie', | ||
'maintainer': 'Applix', | ||
'license': 'LGPL-3', | ||
'category': '', | ||
'depends': [ | ||
'sale_management', | ||
'payment_mollie_official' | ||
], | ||
'data': [ | ||
'views/sale_order.xml', | ||
'views/payment_acquirer.xml', | ||
'data/cron.xml' | ||
], | ||
|
||
'images': [ | ||
'static/description/cover.png', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="sync_shipment_cron" model="ir.cron"> | ||
<field name="name">Mollie: sync shipment data</field> | ||
<field name="model_id" ref="sale.model_sale_order"/> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">hours</field> | ||
<field name="numbercall">-1</field> | ||
<field name="state">code</field> | ||
<field name="code">model._cron_mollie_sync_shipment()</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from . import sale_order | ||
from . import payment_acquirer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from odoo import _, api, fields, models | ||
from mollie.api.error import UnprocessableEntityError | ||
|
||
|
||
class PaymentAcquirerMollie(models.Model): | ||
_inherit = 'payment.acquirer' | ||
|
||
mollie_auto_sync_shipment = fields.Boolean() | ||
|
||
# ----------------------------------------------- | ||
# Methods that uses to mollie python lib | ||
# ----------------------------------------------- | ||
|
||
def _api_mollie_sync_shipment(self, order_reference, shipment_data): | ||
order = self._api_mollie_get_order(order_reference) | ||
try: | ||
shipment = order.create_shipment(shipment_data) | ||
except UnprocessableEntityError as e: | ||
return {'error': str(e)} | ||
return shipment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from odoo import _, api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
mollie_payment = fields.Boolean(compute='_compute_mollie_payment') | ||
mollie_need_shipment_sync = fields.Boolean(compute='_compute_mollie_need_shipment_sync', store=True) | ||
|
||
def mollie_sync_shipment_data(self): | ||
transaction = self._mollie_get_valid_transaction() | ||
if transaction: | ||
data = transaction.acquirer_id._mollie_get_payment_data(transaction.acquirer_reference) | ||
shipment_lines = [] | ||
if data and data.get('lines'): | ||
for mollie_line in data.get('lines'): | ||
mollie_line_metadata = mollie_line.get('metadata') | ||
if mollie_line_metadata: | ||
order_line = self.order_line.filtered(lambda l: l.id == mollie_line_metadata.get('line_id')) | ||
if order_line and order_line.qty_delivered > mollie_line['quantityShipped']: | ||
qty_to_ship = order_line.qty_delivered - mollie_line['quantityShipped'] | ||
if qty_to_ship and mollie_line.get('shippableQuantity') >= qty_to_ship: | ||
shipment_lines.append({ | ||
'id': mollie_line['id'], | ||
'quantity': int(qty_to_ship) # mollie does not support float values | ||
}) | ||
if shipment_lines: | ||
transaction.acquirer_id._api_mollie_sync_shipment(transaction.acquirer_reference, {'lines': shipment_lines}) | ||
|
||
# For all the cases we will un-mark the sales orders | ||
self.mollie_need_shipment_sync = False | ||
|
||
def _compute_mollie_payment(self): | ||
for order in self: | ||
valid_transaction = order._mollie_get_valid_transaction() | ||
order.mollie_payment = len(valid_transaction) >= 1 | ||
|
||
@api.depends('order_line.qty_delivered') | ||
def _compute_mollie_need_shipment_sync(self): | ||
for order in self: | ||
if order.mollie_payment: | ||
order.mollie_need_shipment_sync = True | ||
else: | ||
order.mollie_need_shipment_sync = False | ||
|
||
def _mollie_get_valid_transaction(self): | ||
self.ensure_one() | ||
return self.transaction_ids.filtered(lambda t: t.acquirer_id.provider == 'mollie' and t.state in ['authorized', 'done'] and t.acquirer_reference.startswith("ord_")) | ||
|
||
def _cron_mollie_sync_shipment(self): | ||
mollie_acquirer = self.env.ref('payment_mollie_official.payment_acquirer_mollie') | ||
if mollie_acquirer.mollie_auto_sync_shipment: | ||
orders = self.search([('mollie_need_shipment_sync', '=', True)]) | ||
for order in orders: | ||
order.mollie_sync_shipment_data() | ||
self.env.cr.commit() | ||
return True |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<div class="row py-3"> | ||
<div class="col-md-6 py-3"> | ||
<img src="//apps.odoocdn.com/apps/assets/14.0/payment_mollie_official/img/icon-rect.png?5daf2f9"> | ||
<h1 style="color:#000; font-weight:bold"> | ||
Sync <b style="font-weight:bolder; color:#0077ff">shipment</b> | ||
data from odoo to mollie. | ||
</h1> | ||
<div class="alert alert-warning"> | ||
<i class="fa fa-exclamation-triangle"></i> Make sure you are using <b>Mollie payment</b> module >= 14.0.0.5 | ||
</div> | ||
</div> | ||
<div class="col-md-6"> | ||
<img class="img img-fluid shadow" src="mollie_1.png" style="background-color:#f8f9fa; padding:9px 0px; border-radius:10px; border:1px solid #cccccc7a; padding-top:10px"> | ||
</div> | ||
</div> | ||
<h1 style="color:#000; font-weight:bold; font-size:50px" class="mt-5 text-center mb-0">How to configure</h1> | ||
<div class="text-center text-muted" style="font-weight:400; margin-bottom:18px"> | ||
<span style="width:73px; height:10px; display:inline-block; border-radius:4px; background-color:#0077ff"> </span> | ||
</div> | ||
<h3> | ||
<span class="badge badge-pill mr-2" style="background-color:#0077ff; color:#fff; padding:5px 17px; font-size:14px"> Step 1 </span> | ||
<span style="display:inline-block; font-size:19px"> Download the module and place the module in apps folder and install the module. </span> | ||
</h3> | ||
|
||
|
||
<h1 style="color:#000; font-weight:bold; font-size:50px" class="mt-5 text-center mb-0">How to Use it</h1> | ||
<div class="text-center text-muted" style="font-weight:400; margin-bottom:18px"> | ||
<span style="width:73px; height:10px; display:inline-block; border-radius:4px; background-color:#0077ff"> </span> | ||
</div> | ||
<h3> | ||
<span class="badge badge-pill mr-2" style="background-color:#0077ff; color:#fff; padding:5px 17px; font-size:14px"> | ||
Step 1 </span> | ||
<span style="display:inline-block; font-size:19px"> After installation, you will see the | ||
<span style="color:#0077ff"> Sync Shipment </span> button on order (if it is paid with mollie) | ||
</span> | ||
</h3> | ||
<h3> | ||
<span class="badge badge-pill mr-2" style="background-color:#0077ff; color:#fff; padding:5px 17px; font-size:14px"> | ||
Step 2 </span> | ||
<span style="display:inline-block; font-size:19px"> Clicking on <span style="color:#0077ff">Sync Shipment </span> | ||
button will sync shipment data with mollie. | ||
</h3> | ||
|
||
<div class="alert alert-info mt-1 d-inline-block" style="margin-left: 95px;background-color: #dfeeff;color: #0077ff;"> | ||
You can enable, automatic shipment sync from the settings of mollie payment. | ||
</div> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="payment_acquirer_inh_view_form" model="ir.ui.view"> | ||
<field name="name">payment.acquirer.view.form</field> | ||
<field name="model">payment.acquirer</field> | ||
<field name="inherit_id" ref="payment_mollie_official.acquirer_form_view_mollie"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//group/small" position="after"> | ||
<field name="mollie_auto_sync_shipment" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="sale_order_inh_view_form" model="ir.ui.view"> | ||
<field name="name">sale.order.view.form</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="state" position="before"> | ||
<button name="mollie_sync_shipment_data" attrs="{'invisible': [('mollie_payment', '=', False)]}" type="object" string="Sync Shipment"/> | ||
<field name="mollie_payment" invisible="1"/> | ||
<field name="mollie_need_shipment_sync" invisible="1"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters