diff --git a/sale_order_rental/README.rst b/sale_order_rental/README.rst new file mode 100644 index 00000000..e47289c8 --- /dev/null +++ b/sale_order_rental/README.rst @@ -0,0 +1,28 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================= +Sale order rental +================= + +* This module put the start date, end date and rental days in sale orders, delivery notes and invoices. + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ +* Ana Juaristi +* Oihana Larrañaga + +Do not contact contributors directly about support or help with technical issues. diff --git a/sale_order_rental/__init__.py b/sale_order_rental/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/sale_order_rental/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_order_rental/__manifest__.py b/sale_order_rental/__manifest__.py new file mode 100644 index 00000000..1bf63436 --- /dev/null +++ b/sale_order_rental/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2019 Oihana Larrañaga - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +{ + "name": "Sale Order Rental", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "depends": [ + "sale_management", + "stock", + ], + "author": "AvanzOSC", + "website": "http://www.avanzosc.es", + "category": "Sales", + "data": [ + "security/ir.model.access.csv", + "views/sale_order_view.xml", + "views/stock_picking_view.xml", + "views/account_invoice_view.xml", + ], + "installable": True, +} diff --git a/sale_order_rental/i18n/es.po b/sale_order_rental/i18n/es.po new file mode 100644 index 00000000..d57371c8 --- /dev/null +++ b/sale_order_rental/i18n/es.po @@ -0,0 +1,98 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_rental +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-07-30 07:20+0000\n" +"PO-Revision-Date: 2019-07-30 07:20+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice_line__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order_line__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_move__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_picking__expected_delivery_date +msgid "Expected delivery date" +msgstr "Fecha inicio" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice_line__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order_line__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_move__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_picking__expected_end_date +msgid "Expected end date" +msgstr "Fecha fin" + +#. module: sale_order_rental +#: code:addons/sale_order_rental/models/sale_order.py:37 +#: code:addons/sale_order_rental/models/sale_order.py:96 +#, python-format +msgid "Expected end date must be greater than expected delivery date" +msgstr "La fecha fin tiene que ser mayor que la fecha inicio" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_account_invoice +msgid "Invoice" +msgstr "Factura" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_account_invoice_line +msgid "Invoice Line" +msgstr "Linea de Factura" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice_line__rental_days +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order__rental_days +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order_line__rental_days +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_move__rental_days +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_picking__rental_days +msgid "Rental days" +msgstr "Días de alquiler" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_stock_return_picking +msgid "Return Picking" +msgstr "Albarán de devolución" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_sale_order +msgid "Sale Order" +msgstr "Pedido de venta" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice__sale_order_id +msgid "Sale order" +msgstr "Pedido" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de pedido de venta" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_stock_move +msgid "Stock Move" +msgstr "Movimiento de existencias" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_stock_picking +msgid "Transfer" +msgstr "Transferir" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice__rental_days +msgid "rental days" +msgstr "Días de alquiler" + diff --git a/sale_order_rental/i18n/sale_order_rental.pot b/sale_order_rental/i18n/sale_order_rental.pot new file mode 100644 index 00000000..0917cfc2 --- /dev/null +++ b/sale_order_rental/i18n/sale_order_rental.pot @@ -0,0 +1,98 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_rental +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-07-30 07:20+0000\n" +"PO-Revision-Date: 2019-07-30 07:20+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice_line__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order_line__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_move__expected_delivery_date +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_picking__expected_delivery_date +msgid "Expected delivery date" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice_line__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order_line__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_move__expected_end_date +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_picking__expected_end_date +msgid "Expected end date" +msgstr "" + +#. module: sale_order_rental +#: code:addons/sale_order_rental/models/sale_order.py:37 +#: code:addons/sale_order_rental/models/sale_order.py:96 +#, python-format +msgid "Expected end date must be greater than expected delivery date" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_account_invoice +msgid "Invoice" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_account_invoice_line +msgid "Invoice Line" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice_line__rental_days +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order__rental_days +#: model:ir.model.fields,field_description:sale_order_rental.field_sale_order_line__rental_days +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_move__rental_days +#: model:ir.model.fields,field_description:sale_order_rental.field_stock_picking__rental_days +msgid "Rental days" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_stock_return_picking +msgid "Return Picking" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_sale_order +msgid "Sale Order" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice__sale_order_id +msgid "Sale order" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model,name:sale_order_rental.model_stock_picking +msgid "Transfer" +msgstr "" + +#. module: sale_order_rental +#: model:ir.model.fields,field_description:sale_order_rental.field_account_invoice__rental_days +msgid "rental days" +msgstr "" + diff --git a/sale_order_rental/models/__init__.py b/sale_order_rental/models/__init__.py new file mode 100644 index 00000000..5f20f2c0 --- /dev/null +++ b/sale_order_rental/models/__init__.py @@ -0,0 +1,3 @@ +from . import sale_order +from . import stock +from . import account_invoice diff --git a/sale_order_rental/models/account_invoice.py b/sale_order_rental/models/account_invoice.py new file mode 100644 index 00000000..04c50ecb --- /dev/null +++ b/sale_order_rental/models/account_invoice.py @@ -0,0 +1,105 @@ +# Copyright 2019 Oihana Larrañaga - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo import models, fields, api + + +class AccountInvoice(models.Model): + _inherit = 'account.invoice' + + sale_order_id = fields.Many2one( + string='Sale order', comodel_name='sale.order') + expected_delivery_date = fields.Date( + string='Expected delivery date', + related='sale_order_id.expected_delivery_date') + expected_end_date = fields.Date( + string='Expected end date', related='sale_order_id.expected_end_date') + rental_days = fields.Integer( + string='rental days', related='sale_order_id.rental_days') + + @api.multi + def get_taxes_values(self): + tax_grouped = {} + round_curr = self.currency_id.round + for line in self.invoice_line_ids: + if not line.account_id: + continue + price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0) + if line.rental_days: + taxes = line.invoice_line_tax_ids.compute_all( + price_unit, self.currency_id, + line.quantity * line.rental_days, + line.product_id, self.partner_id)['taxes'] + else: + taxes = line.invoice_line_tax_ids.compute_all( + price_unit, self.currency_id, line.quantity, + line.product_id, self.partner_id)['taxes'] + for tax in taxes: + val = self._prepare_tax_line_vals(line, tax) + key = self.env['account.tax'].browse( + tax['id']).get_grouping_key(val) + if key not in tax_grouped: + tax_grouped[key] = val + tax_grouped[key]['base'] = round_curr(val['base']) + else: + tax_grouped[key]['amount'] += val['amount'] + tax_grouped[key]['base'] += round_curr(val['base']) + return tax_grouped + + +class AccountInvoiceLine(models.Model): + _inherit = 'account.invoice.line' + + expected_delivery_date = fields.Date( + string='Expected delivery date', + compute='_compute_expected_delivery_date', store=True) + expected_end_date = fields.Date( + string='Expected end date', + compute='_compute_expected_end_date', store=True) + rental_days = fields.Integer( + string='Rental days', + compute='_compute_rental_days', store=True) + + @api.depends('sale_line_ids', 'sale_line_ids.expected_delivery_date') + def _compute_expected_delivery_date(self): + for line in self: + for sale_line in line.sale_line_ids: + line.expected_delivery_date = ( + sale_line.expected_delivery_date if + sale_line.expected_delivery_date else False) + + @api.depends('sale_line_ids', 'sale_line_ids.expected_end_date') + def _compute_expected_end_date(self): + for line in self: + for sale_line in line.sale_line_ids: + line.expected_end_date = ( + sale_line.expected_end_date if + sale_line.expected_end_date else False) + + @api.depends('sale_line_ids', 'sale_line_ids.rental_days') + def _compute_rental_days(self): + for line in self: + for sale_line in line.sale_line_ids: + line.rental_days = ( + sale_line.rental_days if sale_line.rental_days else 0) + + @api.depends('price_unit', 'discount', 'invoice_line_tax_ids', 'quantity', + 'rental_days', 'product_id', 'invoice_id.partner_id', + 'invoice_id.currency_id', 'invoice_id.company_id', + 'invoice_id.date_invoice', 'invoice_id.date') + def _compute_price(self): + for line in self: + if line.rental_days: + price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) + taxes = line.invoice_line_tax_ids.compute_all( + price, line.invoice_id.currency_id, + line.quantity * line.rental_days, + product=line.product_id, + partner=line.invoice_id.partner_shipping_id) + line.update({ + 'price_tax': sum( + t.get('amount', 0.0) for t in taxes.get('taxes', [])), + 'price_total': taxes['total_included'], + 'price_subtotal': taxes['total_excluded'], + }) + else: + super(AccountInvoiceLine, line)._compute_price() diff --git a/sale_order_rental/models/sale_order.py b/sale_order_rental/models/sale_order.py new file mode 100644 index 00000000..34214b21 --- /dev/null +++ b/sale_order_rental/models/sale_order.py @@ -0,0 +1,150 @@ +# Copyright 2019 Oihana Larrañaga - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + expected_delivery_date = fields.Date( + string='Expected delivery date') + expected_end_date = fields.Date( + string='Expected end date') + rental_days = fields.Integer( + string='Rental days', compute='_compute_rental_days', store=True) + + @api.depends('expected_delivery_date', 'expected_end_date') + def _compute_rental_days(self): + for order in self: + order.rental_days = 0 + if order.expected_delivery_date and order.expected_end_date: + order.rental_days = abs( + order.expected_end_date-order.expected_delivery_date + ).days + 1 + + @api.onchange('expected_delivery_date') + def onchange_expected_delivery_date(self): + self.commitment_date = (fields.Datetime.to_datetime( + self.expected_delivery_date) if self.expected_delivery_date else + False) + if self.expected_delivery_date: + self.order_line.write({'expected_delivery_date': + self.expected_delivery_date}) + if not self.expected_delivery_date: + self.order_line.write({'expected_delivery_date': False}) + + @api.onchange('expected_end_date') + def onchange_expected_end_date(self): + if (self.expected_delivery_date and self.expected_end_date and + self.expected_delivery_date > self.expected_end_date): + raise ValidationError( + _('Expected end date must be greater than expected delivery ' + 'date')) + if self.expected_end_date: + self.order_line.write({'expected_end_date': + self.expected_end_date}) + if not self.expected_end_date: + self.order_line.write({'expected_end_date': False}) + + @api.multi + def action_confirm(self): + res = super(SaleOrder, self).action_confirm() + for sale in self: + for picking in sale.picking_ids.filtered( + lambda l: l.expected_end_date): + vals = { + 'location_id': picking.location_dest_id.id, + 'location_dest_id': picking.location_id.id, + 'picking_type_id': + picking.picking_type_id.return_picking_type_id.id} + if picking.expected_end_date: + vals['scheduled_date'] = ( + "{} 08:00:00".format(picking.expected_end_date)) + new_picking = picking.copy(vals) + for move in new_picking.move_lines: + if move.expected_end_date: + vals = { + 'location_id': new_picking.location_id.id, + 'location_dest_id': + new_picking.location_dest_id.id} + if move.expected_end_date: + vals['date_expected'] = ( + "{} 08:00:00".format(move.expected_end_date)) + move.write(vals) + move._action_confirm() + if not move.expected_end_date: + move.unlink() + return res + + @api.multi + def _prepare_invoice(self): + invoice_vals = super(SaleOrder, self)._prepare_invoice() + invoice_vals['sale_order_id'] = self.id + return invoice_vals + + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + expected_delivery_date = fields.Date( + string='Expected delivery date') + expected_end_date = fields.Date( + string='Expected end date', ) + rental_days = fields.Integer( + string='Rental days', compute='_compute_rental_days', store=True) + + @api.depends('expected_delivery_date', 'expected_end_date') + def _compute_rental_days(self): + for line in self.filtered(lambda l: l.expected_delivery_date and + l.expected_end_date): + if line.expected_delivery_date > line.expected_end_date: + raise ValidationError( + _('Expected end date must be greater than expected ' + 'delivery date')) + else: + line.rental_days = abs( + line.expected_end_date - line.expected_delivery_date + ).days + 1 + + @api.multi + @api.onchange('product_id') + def product_id_change(self): + result = super(SaleOrderLine, self).product_id_change() + if self.order_id.expected_delivery_date: + self.expected_delivery_date = self.order_id.expected_delivery_date + if self.order_id.expected_end_date: + self.expected_end_date = self.order_id.expected_end_date + return result + + @api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id', + 'rental_days') + def _compute_amount(self): + for line in self: + if line.rental_days: + price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) + taxes = line.tax_id.compute_all( + price, line.order_id.currency_id, + line.product_uom_qty * line.rental_days, + product=line.product_id, + partner=line.order_id.partner_shipping_id) + line.update({ + 'price_tax': sum( + t.get('amount', 0.0) for t in taxes.get('taxes', [])), + 'price_total': taxes['total_included'], + 'price_subtotal': taxes['total_excluded'], + }) + else: + super(SaleOrderLine, line)._compute_amount() + + @api.multi + def invoice_line_create_vals(self, invoice_id, qty): + res = super( + SaleOrderLine, self).invoice_line_create_vals(invoice_id, qty) + for result in res: + if result.get('sale_line_ids', False): + a = result.get('sale_line_ids') + sale_line_id = a[0][2][0] + if sale_line_id: + result['sale_order_line_id'] = sale_line_id + return res diff --git a/sale_order_rental/models/stock.py b/sale_order_rental/models/stock.py new file mode 100644 index 00000000..ee955a87 --- /dev/null +++ b/sale_order_rental/models/stock.py @@ -0,0 +1,26 @@ +# Copyright 2019 Oihana Larrañaga - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo import models, fields + + +class StockPicking(models.Model): + _inherit = 'stock.picking' + + expected_delivery_date = fields.Date( + related='sale_id.expected_delivery_date') + expected_end_date = fields.Date( + string='Expected end date', related='sale_id.expected_end_date') + rental_days = fields.Integer( + related='sale_id.rental_days') + + +class StockMove(models.Model): + _inherit = 'stock.move' + + expected_delivery_date = fields.Date( + related='sale_line_id.expected_delivery_date', readonly=False) + expected_end_date = fields.Date( + string='Expected end date', + related='sale_line_id.expected_end_date', readonly=False) + rental_days = fields.Integer( + related='sale_line_id.rental_days') diff --git a/sale_order_rental/security/ir.model.access.csv b/sale_order_rental/security/ir.model.access.csv new file mode 100644 index 00000000..0921b85f --- /dev/null +++ b/sale_order_rental/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +sale_order_model_manager,sale_order_model_manager,model_sale_order,,1,1,1,1 +sale_order_model_user,sale_order_model_user,model_sale_order,,1,0,0,0 diff --git a/sale_order_rental/static/img/enviado.png b/sale_order_rental/static/img/enviado.png new file mode 100644 index 00000000..412cb943 Binary files /dev/null and b/sale_order_rental/static/img/enviado.png differ diff --git a/sale_order_rental/tests/__init__.py b/sale_order_rental/tests/__init__.py new file mode 100644 index 00000000..c06f7b12 --- /dev/null +++ b/sale_order_rental/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2019 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from . import test_sale_order_rental diff --git a/sale_order_rental/tests/test_sale_order_rental.py b/sale_order_rental/tests/test_sale_order_rental.py new file mode 100644 index 00000000..a146abc6 --- /dev/null +++ b/sale_order_rental/tests/test_sale_order_rental.py @@ -0,0 +1,106 @@ +# Copyright 2019 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError +from odoo import fields +from asn1crypto._ffi import null + + +class TestSaleOrderRental(TransactionCase): + + def setUp(self): + super(TestSaleOrderRental, self).setUp() + self.wiz_obj = self.env['sale.advance.payment.inv'] + cond = [('type_tax_use', '=', 'sale'), + ('amount', '>', 1)] + self.tax = self.env['account.tax'].search(cond, limit=1) + cond = [('state', '=', 'draft')] + self.sale_order = self.env['sale.order'].search(cond, limit=1) + self.sale_order.write( + {'expected_delivery_date': '2015-06-09', + 'expected_end_date': '2015-06-15'}) + self.sale_order.order_line.write( + {'tax_id': [(6, 0, self.tax.ids)]}) + self.sale_order.onchange_expected_end_date() + self.sale_order.onchange_expected_delivery_date() + + def test_sale_order_rental(self): + self.sale_order.expected_delivery_date = '2015-06-16' + with self.assertRaises(ValidationError): + self.sale_order.onchange_expected_end_date() + with self.assertRaises(ValidationError): + self.sale_order.order_line[0].expected_delivery_date = '2015-06-16' + self.sale_order.expected_delivery_date = '2015-06-10' + self.sale_order.onchange_expected_delivery_date() + for line in self.sale_order.order_line: + self.assertEquals(line.expected_delivery_date, + fields.Date.from_string('2015-06-10')) +# self.sale_order.expected_end_date = '2015-06-16' + for line in self.sale_order.order_line: + self.assertEquals(line.expected_end_date, + fields.Date.from_string('2015-06-15')) + + self.sale_order.order_line[0].product_id_change() + lines = self.sale_order.mapped('order_line').filtered( + lambda x: not x.expected_end_date or + x.expected_end_date != fields.Date.from_string('2015-06-15')) + self.assertEquals(len(lines), 0) + lines = self.sale_order.mapped('order_line').filtered( + lambda x: not x.expected_delivery_date or + x.expected_delivery_date != fields.Date.from_string('2015-06-10')) + self.assertEquals(len(lines), 0) + self.assertEquals(self.sale_order.commitment_date.date(), + self.sale_order.expected_delivery_date) + self.assertEquals(self.sale_order.rental_days, 6) + self.sale_order.action_confirm() + self.assertEquals(len(self.sale_order.picking_ids), 2) + return_picking = self.sale_order.picking_ids[0] + out_picking = self.sale_order.picking_ids[1] + self.assertEquals(return_picking.location_id, + out_picking.location_dest_id) + self.assertEquals(return_picking.location_dest_id, + out_picking.location_id) + self.assertEquals(return_picking.picking_type_id, + out_picking.picking_type_id.return_picking_type_id) + self.assertEquals(return_picking.scheduled_date, + fields.Datetime.from_string('2015-06-15 08:00:00')) + for move in return_picking.move_lines: + self.assertEquals(move.location_id, return_picking.location_id) + self.assertEquals(move.location_dest_id, + return_picking.location_dest_id) + self.assertEquals( + move.date_expected, + fields.Datetime.from_string('2015-06-15 08:00:00')) + out_picking.move_lines[0].quantity_done = ( + out_picking.move_lines[0].product_uom_qty) + out_picking.button_validate() + wiz = self.wiz_obj.with_context( + active_ids=[self.sale_order.id]).create( + {'advance_payment_method': 'delivered'}) + wiz.with_context(active_ids=[self.sale_order.id]).create_invoices() + self.sale_order.write( + {'expected_delivery_date': False, + 'expected_end_date': False}) + self.sale_order.onchange_expected_end_date() + self.sale_order.onchange_expected_delivery_date() + invoice_line = self.sale_order.invoice_ids[0].invoice_line_ids[0] + + self.sale_order.expected_delivery_date = '2015-06-05' + for invoice_line in self.sale_order.invoice_ids: + self.assertEquals(invoice_line.expected_delivery_date, + fields.Date.from_string('2015-06-05')) + self.sale_order.expected_end_date = '2015-06-10' + for invoice_line in self.sale_order.invoice_ids: + self.assertEquals(invoice_line.expected_end_date, + fields.Date.from_string('2015-06-10')) +# self.sale_order.rental_days = '6' + for invoice_line in self.sale_order.invoice_ids: + self.assertEquals(invoice_line.rental_days, + 6) + invoice_line.invoice_line_tax_ids = [(6, 0, self.tax.ids)] + invoice_line.copy() + tax = self.sale_order.invoice_ids[0].with_context( + rental_days=[null]).get_taxes_values() + for key in tax: + if 'tax_id' in tax[key]: + self.assertEquals(tax[key].get('tax_id'), self.tax.id) diff --git a/sale_order_rental/views/account_invoice_view.xml b/sale_order_rental/views/account_invoice_view.xml new file mode 100644 index 00000000..5f07f805 --- /dev/null +++ b/sale_order_rental/views/account_invoice_view.xml @@ -0,0 +1,19 @@ + + + + account.invoice + + + + + + + + + + + + + + + diff --git a/sale_order_rental/views/sale_order_view.xml b/sale_order_rental/views/sale_order_view.xml new file mode 100644 index 00000000..508a2949 --- /dev/null +++ b/sale_order_rental/views/sale_order_view.xml @@ -0,0 +1,41 @@ + + + + sale.order + + + + + + + + + + + sale.order + + + + + + + + + + + sale.order + + + + + + + + + + + + + + + diff --git a/sale_order_rental/views/stock_picking_view.xml b/sale_order_rental/views/stock_picking_view.xml new file mode 100644 index 00000000..3480b682 --- /dev/null +++ b/sale_order_rental/views/stock_picking_view.xml @@ -0,0 +1,30 @@ + + + + stock.picking + + + + + + + + + + + + + + + + stock.picking + + + + + + + + + +