-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] sale_order_rental: This module put the start date, end date and…
- Loading branch information
1 parent
5da47b2
commit ebe63f1
Showing
16 changed files
with
715 additions
and
0 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,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 | ||
<https://github.com/avanzosc/sale-addons/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 <[email protected]> | ||
* Oihana Larrañaga <[email protected]> | ||
|
||
Do not contact contributors directly about support or help with technical issues. |
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 @@ | ||
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,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, | ||
} |
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,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" | ||
|
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,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 "" | ||
|
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 @@ | ||
from . import sale_order | ||
from . import stock | ||
from . import account_invoice |
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,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() |
Oops, something went wrong.