Skip to content

Commit

Permalink
[IMP] stock_incoterm_extension: destination_port and type in purchase…
Browse files Browse the repository at this point in the history
… orders (#161)
  • Loading branch information
agaldona authored and oihane committed Jul 24, 2017
1 parent d5abf91 commit 6c737dc
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 21 deletions.
6 changes: 4 additions & 2 deletions stock_incoterm_extension/__openerp__.py
Expand Up @@ -21,7 +21,8 @@
"version": "8.0.1.0.0",
"license": "AGPL-3",
"depends": ["stock_account",
"sale_stock"],
"sale_stock",
"purchase"],
"author": "OdooMRP team,"
"AvanzOSC,"
"Serv. Tecnol. Avanzados - Pedro M. Baeza",
Expand All @@ -30,7 +31,8 @@
'data': ["security/ir.model.access.csv",
"views/stock_view.xml",
"views/account_invoice_view.xml",
"views/sale_order_view.xml"],
"views/sale_order_view.xml",
"views/purchase_order_view.xml"],
'installable': True,
'auto_install': False,
}
1 change: 1 addition & 0 deletions stock_incoterm_extension/models/__init__.py
Expand Up @@ -19,3 +19,4 @@
from . import sale_order
from . import stock
from . import account_invoice
from . import purchase_order
13 changes: 8 additions & 5 deletions stock_incoterm_extension/models/account_invoice.py
Expand Up @@ -16,20 +16,23 @@
#
##############################################################################

from openerp import models, fields
from openerp import models, fields, api


class AccountInvoice(models.Model):

_inherit = 'account.invoice'

@api.model
def _get_selection_transport_type(self):
return self.env['sale.order'].fields_get(
allfields=['transport_type'])['transport_type']['selection']

incoterm = fields.Many2one('stock.incoterms', string="Incoterm")
req_destination_port = fields.Boolean(string="Requires destination port",
related="incoterm.destination_port")
req_transport_type = fields.Boolean(string="Requires transport type",
related="incoterm.transport_type")
destination_port = fields.Char(string="Destination port")
transport_type = fields.Selection([('air', 'Air'),
('maritime', 'Maritime'),
('ground', 'Ground')],
string="Transport type")
transport_type = fields.Selection(
selection='_get_selection_transport_type', string="Transport type")
35 changes: 35 additions & 0 deletions stock_incoterm_extension/models/purchase_order.py
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Ainara Galdona - Avanzosc S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields, api


class PurchaseOrder(models.Model):

_inherit = 'purchase.order'

@api.model
def _get_selection_transport_type(self):
return self.env['sale.order'].fields_get(
allfields=['transport_type'])['transport_type']['selection']

req_destination_port = fields.Boolean(
string="Requires destination port",
related="incoterm_id.destination_port")
req_transport_type = fields.Boolean(
string="Requires transport type",
related="incoterm_id.transport_type")
destination_port = fields.Char(string="Destination port")
transport_type = fields.Selection(
selection='_get_selection_transport_type', string="Transport type")

@api.model
def _prepare_invoice(self, order, line_ids):
res = super(PurchaseOrder, self)._prepare_invoice(order, line_ids)
res.update({
'incoterm': order.incoterm_id.id,
'destination_port': order.destination_port,
'transport_type': order.transport_type
})
return res
15 changes: 8 additions & 7 deletions stock_incoterm_extension/models/sale_order.py
Expand Up @@ -28,15 +28,16 @@ class SaleOrder(models.Model):
req_transport_type = fields.Boolean(string="Requires transport type",
related="incoterm.transport_type")
destination_port = fields.Char(string="Destination port")
transport_type = fields.Selection([('air', 'Air'),
('maritime', 'Maritime'),
('ground', 'Ground')],
string="Transport type")
transport_type = fields.Selection(
selection=[('air', 'Air'), ('maritime', 'Maritime'),
('ground', 'Ground')], string="Transport type")

@api.model
def _prepare_invoice(self, order, line_ids):
res = super(SaleOrder, self)._prepare_invoice(order, line_ids)
res['incoterm'] = order.incoterm.id
res['destination_port'] = order.destination_port
res['transport_type'] = order.transport_type
res.update({
'incoterm': order.incoterm.id,
'destination_port': order.destination_port,
'transport_type': order.transport_type
})
return res
19 changes: 12 additions & 7 deletions stock_incoterm_extension/models/stock.py
Expand Up @@ -31,24 +31,29 @@ class StockPicking(models.Model):

_inherit = 'stock.picking'

@api.model
def _get_selection_transport_type(self):
return self.env['sale.order'].fields_get(
allfields=['transport_type'])['transport_type']['selection']

incoterm = fields.Many2one('stock.incoterms', string="Incoterm")
req_destination_port = fields.Boolean(string="Requires destination port",
related="incoterm.destination_port")
req_transport_type = fields.Boolean(string="Requires transport type",
related="incoterm.transport_type")
destination_port = fields.Char(string="Destination port")
transport_type = fields.Selection([('air', 'Air'),
('maritime', 'Maritime'),
('ground', 'Ground')],
string="Transport type")
transport_type = fields.Selection(
selection='_get_selection_transport_type', string="Transport type")

@api.model
def _create_invoice_from_picking(self, picking, vals):
if picking and picking.sale_id:
sale = picking.sale_id
vals['incoterm'] = sale.incoterm and sale.incoterm.id or False
vals['destination_port'] = sale.destination_port
vals['transport_type'] = sale.transport_type
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)

Expand Down
5 changes: 5 additions & 0 deletions stock_incoterm_extension/tests/__init__.py
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Ainara Galdona - Avanzosc S.L.
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import test_stock_incoterm_extension
52 changes: 52 additions & 0 deletions stock_incoterm_extension/tests/test_stock_incoterm_extension.py
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Ainara Galdona - Avanzosc S.L.
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp.tests import common


class TestStockIncotermExtension(common.TransactionCase):

def setUp(self):
super(TestStockIncotermExtension, self).setUp()
self.invoice_model = self.env['account.invoice']
self.journal = self.env.ref('account.sales_journal')
self.sale_order = self.env.ref('sale.sale_order_2')
self.sale_order1 = self.env.ref('sale.sale_order_1')
self.purchase_order = self.env.ref('purchase.purchase_order_1')
self.incoterm = self.env.ref('stock.incoterm_EXW')
self.incoterm.destination_port = False
self.incoterm.transport_type = True
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'

def test_sale_order_invoice(self):
self.sale_order.order_policy = 'manual'
self.sale_order.action_button_confirm()
res = self.sale_order.manual_invoice()
inv_id = res.get('res_id', False)
invoice = self.invoice_model.browse(inv_id)
self.assertTrue(invoice and invoice.incoterm.id == self.incoterm.id and
invoice.transport_type == 'air')

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.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(
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')
18 changes: 18 additions & 0 deletions stock_incoterm_extension/views/purchase_order_view.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="arch" type="xml">
<field name="incoterm_id" position="after">
<field name="req_destination_port" invisible="1"/>
<field name="req_transport_type" invisible="1"/>
<field name="destination_port" attrs="{'required':[('req_destination_port', '=', True)]}"/>
<field name="transport_type" attrs="{'required':[('req_transport_type', '=', True)]}"/>
</field>
</field>
</record>
</data>
</openerp>

0 comments on commit 6c737dc

Please sign in to comment.