Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] sale_order_rental: This module put the start date, end date and… #50

Merged
merged 3 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions sale_order_rental/README.rst
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.
2 changes: 2 additions & 0 deletions sale_order_rental/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
21 changes: 21 additions & 0 deletions sale_order_rental/__manifest__.py
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,
}
98 changes: 98 additions & 0 deletions sale_order_rental/i18n/es.po
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"

98 changes: 98 additions & 0 deletions sale_order_rental/i18n/sale_order_rental.pot
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 ""

6 changes: 6 additions & 0 deletions sale_order_rental/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from . import sale_order
from . import sale_order_line
from . import stock_picking
from . import stock_move
from . import account_invoice
from . import account_invoice_line
65 changes: 65 additions & 0 deletions sale_order_rental/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2019 Oihana Larrañaga - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import api, fields, models


class AccountInvoice(models.Model):
_inherit = 'account.invoice'

sale_order_id = fields.Many2one(
string='Sale order', comodel_name='sale.order')
sale_expected_delivery_date = fields.Date(
string='Expected Delivery Date',
compute='_compute_rental_dates', store=True)
sale_expected_end_date = fields.Date(
string='Expected Return Date',
compute='_compute_rental_dates', store=True)
rental_days = fields.Integer(
string='Rental Days',
compute='_compute_rental_dates', store=True)

@api.depends('invoice_line_ids',
'invoice_line_ids.sale_expected_delivery_date',
'invoice_line_ids.sale_expected_end_date')
def _compute_rental_dates(self):
for invoice in self.filtered('invoice_line_ids'):
lines = invoice.invoice_line_ids.filtered(
lambda l: l.sale_expected_delivery_date or
l.sale_expected_end_date)
if lines:
invoice.sale_expected_delivery_date = min(lines.mapped(
'sale_expected_delivery_date'))
invoice.sale_expected_end_date = max(lines.mapped(
'sale_expected_end_date'))
invoice.rental_days = ((
invoice.sale_expected_end_date -
invoice.sale_expected_delivery_date).days + 1)

@api.multi
def get_taxes_values(self):
tax_grouped = super(AccountInvoice, self).get_taxes_values()
if any(self.invoice_line_ids.filtered('rental_days')):
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)
quantity = line.quantity
if line.rental_days:
quantity *= line.rental_days
taxes = line.invoice_line_tax_ids.compute_all(
price_unit, self.currency_id, 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
69 changes: 69 additions & 0 deletions sale_order_rental/models/account_invoice_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2019 Oihana Larrañaga - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import api, fields, models


class AccountInvoiceLine(models.Model):
_inherit = 'account.invoice.line'

sale_expected_delivery_date = fields.Date(
string='Expected Delivery Date',
compute='_compute_sale_rental_dates', store=True)
sale_expected_end_date = fields.Date(
string='Expected Return Date',
compute='_compute_sale_rental_dates', store=True)
rental_days = fields.Integer(
string='Rental Days',
compute='_compute_sale_rental_dates', store=True)

@api.depends('sale_line_ids',
'sale_line_ids.expected_delivery_date',
'sale_line_ids.expected_end_date',
'sale_line_ids.rental_days')
def _compute_sale_rental_dates(self):
for line in self.filtered('sale_line_ids'):
sale_lines = line.sale_line_ids.filtered(
lambda l: l.expected_delivery_date and
l.expected_end_date)
if sale_lines:
line.sale_expected_delivery_date = min(sale_lines.mapped(
'expected_delivery_date'))
line.sale_expected_end_date = max(sale_lines.mapped(
'expected_end_date'))
line.rental_days = sum(sale_lines.mapped('rental_days'))

@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:
currency = (
line.invoice_id and line.invoice_id.currency_id or None)
price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
taxes = False
quantity = line.quantity * line.rental_days
if line.invoice_line_tax_ids:
taxes = line.invoice_line_tax_ids.compute_all(
price, currency, quantity, product=line.product_id,
partner=line.invoice_id.partner_id)
line.price_subtotal = price_subtotal_signed = taxes[
'total_excluded'] if taxes else quantity * price
line.price_total = taxes[
'total_included'] if taxes else line.price_subtotal
if (line.invoice_id.currency_id and
line.invoice_id.currency_id !=
line.invoice_id.company_id.currency_id):
currency = line.invoice_id.currency_id
date = line.invoice_id._get_currency_rate_date()
price_subtotal_signed = currency._convert(
price_subtotal_signed,
line.invoice_id.company_id.currency_id,
line.company_id or line.env.user.company_id,
date or fields.Date.today())
sign = line.invoice_id.type in ['in_refund',
'out_refund'] and -1 or 1
line.price_subtotal_signed = price_subtotal_signed * sign
else:
super(AccountInvoiceLine, line)._compute_price()
Loading