Skip to content

Commit

Permalink
[IMP] stock_incoterm_extension: add default destination port
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed May 25, 2018
1 parent 4964554 commit 7354353
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 28 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ coverage.xml

# Translations
*.mo
*.pot

# Pycharm
.idea
Expand All @@ -51,9 +52,15 @@ coverage.xml
# Rope
.ropeproject

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# Backup files
*~
*.swp

.settings/

18 changes: 14 additions & 4 deletions stock_incoterm_extension/README.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

========================
Stock Incoterm Extension
========================
This module adds two new fields on Incoterms, Required Destination Port and Required Transport Type.
Adds new fields in sale orders, pickings and invoices, "Incoterm", "Destination Port" and "Transport Type".
If the incorterm's boolean fields are specified, the fields "Transport Type" and "Destination Port" will be required.

This module adds three new fields on Incoterms, Required Destination Port,
Default Destination Port and Required Transport Type.
It adds new fields in sale orders, pickings, purchase orders and invoices,
"Incoterm", "Destination Port" and "Transport Type".
If the incorterm's boolean fields are specified, the fields "Transport Type"
and "Destination Port" will be required.


Credits
Expand All @@ -14,5 +23,6 @@ Contributors
* Ainara Galdona <ainaragaldona@avanzosc.es>
* Ana Juaristi <anajuaristi@avanzosc.es>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>


Do not contact contributors directly about support or help with technical issues.
33 changes: 19 additions & 14 deletions stock_incoterm_extension/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,26 @@

{
"name": "Stock Incoterm Extension",
"version": "8.0.1.0.0",
"version": "8.0.1.1.0",
"license": "AGPL-3",
"depends": ["stock_account",
"sale_stock",
"purchase"],
"author": "OdooMRP team,"
"AvanzOSC,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza",
"depends": [
"stock_account",
"sale_stock",
"purchase",
],
"author": "OdooMRP team, "
"AvanzOSC, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"Odoo Community Association (OCA)",
"website": "http://www.odoomrp.com",
"category": "Stock",
'data': ["security/ir.model.access.csv",
"views/stock_view.xml",
"views/account_invoice_view.xml",
"views/sale_order_view.xml",
"views/purchase_order_view.xml"],
'installable': True,
'auto_install': False,
"data": [
"security/ir.model.access.csv",
"views/stock_view.xml",
"views/account_invoice_view.xml",
"views/sale_order_view.xml",
"views/purchase_order_view.xml",
],
"installable": True,
"auto_install": False,
}
6 changes: 6 additions & 0 deletions stock_incoterm_extension/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ def _get_selection_transport_type(self):
destination_port = fields.Char(string="Destination port")
transport_type = fields.Selection(
selection='_get_selection_transport_type', string="Transport type")

@api.onchange('incoterm')
def _onchange_incoterm(self):
for invoice in self:
invoice.destination_port = (
invoice.incoterm.default_destination_port)
5 changes: 5 additions & 0 deletions stock_incoterm_extension/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class SaleOrder(models.Model):
selection=[('air', 'Air'), ('maritime', 'Maritime'),
('ground', 'Ground')], string="Transport type")

@api.onchange('incoterm')
def _onchange_incoterm(self):
for order in self:
order.destination_port = order.incoterm.default_destination_port

@api.model
def _prepare_invoice(self, order, line_ids):
res = super(SaleOrder, self)._prepare_invoice(order, line_ids)
Expand Down
22 changes: 14 additions & 8 deletions stock_incoterm_extension/models/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class StockIncoterms(models.Model):

destination_port = fields.Boolean(string="Requires destination port")
transport_type = fields.Boolean(string="Requires transport type")
default_destination_port = fields.Char(string="Default Destination Port")


class StockPicking(models.Model):
Expand All @@ -45,17 +46,22 @@ def _get_selection_transport_type(self):
transport_type = fields.Selection(
selection='_get_selection_transport_type', string="Transport type")

@api.onchange('incoterm')
def _onchange_incoterm(self):
for picking in self:
picking.destination_port = (
picking.incoterm.default_destination_port)

@api.model
def _create_invoice_from_picking(self, picking, vals):
if picking and picking.sale_id:
sale = picking.sale_id
if picking:
vals.update({
'incoterm': sale.incoterm and sale.incoterm.id or False,
'destination_port': sale.destination_port,
'transport_type': sale.transport_type
})
return super(StockPicking, self)._create_invoice_from_picking(picking,
vals)
'incoterm': picking.incoterm and picking.incoterm.id or False,
'destination_port': picking.destination_port,
'transport_type': picking.transport_type,
})
return super(StockPicking, self)._create_invoice_from_picking(
picking, vals)


class StockMove(models.Model):
Expand Down
18 changes: 16 additions & 2 deletions stock_incoterm_extension/tests/test_stock_incoterm_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def setUp(self):
self.incoterm = self.env.ref('stock.incoterm_EXW')
self.incoterm.destination_port = False
self.incoterm.transport_type = True
self.incoterm.default_destination_port = 'port1'
self.sale_order.incoterm = self.incoterm
self.sale_order.transport_type = 'air'
self.sale_order1.incoterm = self.incoterm
self.sale_order1.transport_type = 'ground'
self.sale_order1.destination_port = 'port1'
self.purchase_order.incoterm_id = self.incoterm
self.purchase_order.transport_type = 'maritime'

Expand All @@ -33,20 +33,34 @@ def test_sale_order_invoice(self):
invoice = self.invoice_model.browse(inv_id)
self.assertTrue(invoice and invoice.incoterm.id == self.incoterm.id and
invoice.transport_type == 'air')
self.assertFalse(invoice.destination_port)
invoice._onchange_incoterm()

def test_purchase_order_invoice(self):
self.purchase_order.signal_workflow('purchase_confirm')
invoice = self.purchase_order.invoice_ids and \
self.purchase_order.invoice_ids[0]
self.assertFalse(invoice and invoice.destination_port)
self.assertTrue(invoice and invoice.incoterm.id == self.incoterm.id and
invoice.transport_type == 'maritime')

def test_sale_order_picking_invoice(self):
self.sale_order1.order_policy = 'picking'
self.sale_order1.action_button_confirm()
invoice_ids = self.sale_order1.picking_ids.action_invoice_create(
pickings = self.sale_order1.picking_ids
self.assertFalse(pickings.destination_port)
pickings._onchange_incoterm()
self.assertEquals(pickings.destination_port,
self.incoterm.default_destination_port)
invoice_ids = pickings.action_invoice_create(
journal_id=self.journal.id)
invoices = self.invoice_model.browse(invoice_ids)
self.assertTrue(invoices and invoices[0].incoterm.id ==
self.incoterm.id and invoices[0].transport_type ==
'ground' and invoices[0].destination_port == 'port1')

def test_sale_order_onchange(self):
self.assertTrue(self.incoterm.default_destination_port)
self.sale_order._onchange_incoterm()
self.assertEquals(self.sale_order.destination_port,
self.incoterm.default_destination_port)

0 comments on commit 7354353

Please sign in to comment.