[MIG] sale_usability to v14 (with up-ports from v10)

This commit is contained in:
Alexis de Lattre
2020-12-02 15:12:41 +01:00
parent e505e7e07f
commit 44a4f795d0
16 changed files with 177 additions and 222 deletions

View File

@@ -1,4 +1 @@
from . import sale
from . import account_invoice
from . import product
from . import partner
from . import models

View File

@@ -1,10 +1,10 @@
# Copyright 2014-2019 Akretion (http://www.akretion.com)
# Copyright 2014-2020 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Sale Usability',
'version': '12.0.1.0.0',
'version': '14.0.1.0.0',
'category': 'Sales',
'license': 'AGPL-3',
'summary': 'Usability improvements on sale module',
@@ -15,10 +15,11 @@
'base_view_inheritance_extension',
],
'data': [
'sale_view.xml',
'sale_report_view.xml',
'product_view.xml',
'account_invoice_view.xml',
'views/sale_order.xml',
'views/product_category.xml',
'views/sale_report.xml',
'views/product_pricelist_item.xml',
'views/account_move.xml',
],
'installable': False,
'installable': True,
}

View File

@@ -1,49 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_usability_extension
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-13 11:01+0000\n"
"PO-Revision-Date: 2016-07-13 13:03+0200\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"Language: fr\n"
"X-Generator: Poedit 1.8.7.1\n"
#. module: sale_usability_extension
#: model:ir.model,name:sale_usability_extension.model_account_invoice_line
msgid "Invoice Line"
msgstr "Lignes de facture"
#. module: sale_usability_extension
#: view:sale.order:sale_usability_extension.view_order_form
msgid "Invoices"
msgstr "Factures"
#. module: sale_usability_extension
#: field:account.invoice.line,sale_line_ids:0
msgid "Sale Order Lines"
msgstr "Lignes de Vente"
#. module: sale_usability_extension
#: model:ir.model,name:sale_usability_extension.model_sale_order
msgid "Sales Order"
msgstr "Bon de commande"
#. module: sale_usability_extension
#: view:sale.order:sale_usability_extension.view_order_tree
#: view:sale.order:sale_usability_extension.view_quotation_tree
msgid "Total Untaxed"
msgstr "Total HT"
#. module: sale_usability_extension
#: view:sale.order:sale_usability_extension.view_order_form
msgid "selection"
msgstr "selection"

View File

@@ -1,48 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_usability_extension
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-13 11:01+0000\n"
"PO-Revision-Date: 2016-07-13 11:01+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_usability_extension
#: model:ir.model,name:sale_usability_extension.model_account_invoice_line
msgid "Invoice Line"
msgstr ""
#. module: sale_usability_extension
#: view:sale.order:sale_usability_extension.view_order_form
msgid "Invoices"
msgstr ""
#. module: sale_usability_extension
#: field:account.invoice.line,sale_line_ids:0
msgid "Sale Order Lines"
msgstr ""
#. module: sale_usability_extension
#: model:ir.model,name:sale_usability_extension.model_sale_order
msgid "Sales Order"
msgstr ""
#. module: sale_usability_extension
#: view:sale.order:sale_usability_extension.view_order_tree
#: view:sale.order:sale_usability_extension.view_quotation_tree
msgid "Total Untaxed"
msgstr ""
#. module: sale_usability_extension
#: view:sale.order:sale_usability_extension.view_order_form
msgid "selection"
msgstr ""

View File

@@ -0,0 +1,4 @@
from . import sale_order
from . import account_move
from . import product_template
from . import res_partner

View File

@@ -6,20 +6,19 @@ from odoo import api, fields, models
from collections import OrderedDict
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
class AccountMove(models.Model):
_inherit = 'account.move'
# sale_ids is kind of the symetric field of invoice_ids on sale.order
sale_ids = fields.Many2many(
'sale.order', string='Sale Orders', compute="_compute_sale_ids",
readonly=True, copy=False)
'sale.order', string='Sale Orders', compute="_compute_sale_ids")
sale_count = fields.Integer(
string='Sale Order Count', compute='_compute_sale_ids', readonly=True)
string='Sale Order Count', compute='_compute_sale_ids')
@api.depends('invoice_line_ids.sale_line_ids')
def _compute_sale_ids(self):
for invoice in self:
if invoice.type == 'out_invoice':
if invoice.move_type == 'out_invoice':
sales = invoice.invoice_line_ids.mapped('sale_line_ids').\
mapped('order_id')
invoice.sale_ids = sales.ids
@@ -51,8 +50,8 @@ class AccountInvoice(models.Model):
# {categ(1): {'lines': [l1, l2], 'subtotal': 23.32}}
soo = self.env['sale.order']
for line in self.invoice_line_ids:
order = line.sale_line_ids and line.sale_line_ids[0].order_id\
or soo
order = not line.display_type and line.sale_line_ids and\
line.sale_line_ids[0].order_id or soo
if order in res1:
res1[order]['lines'].append(line)
res1[order]['subtotal'] += line.price_subtotal

View File

@@ -0,0 +1,14 @@
# Copyright 2017-2019 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
service_type = fields.Selection(tracking=True)
expense_policy = fields.Selection(tracking=True)
invoice_policy = fields.Selection(tracking=True)
sale_line_warn = fields.Selection(tracking=True)

View File

@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2019 Akretion France (https://akretion.com/)
# Copyright 2017-2020 Akretion France (https://akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
from odoo import fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
sale_warn = fields.Selection(track_visibility='onchange')
sale_warn = fields.Selection(tracking=True)

View File

@@ -0,0 +1,96 @@
# Copyright (C) 2015-2020 Akretion France (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models, _
from odoo.tools import float_is_zero, float_compare
from odoo.tools.misc import formatLang
class SaleOrder(models.Model):
_inherit = 'sale.order'
date_order = fields.Datetime(tracking=True)
client_order_ref = fields.Char(tracking=True)
# for partner_id, the 'sale' module sets track_visibility='always'
amount_tax = fields.Monetary(tracking=True)
partner_shipping_id = fields.Many2one(tracking=True)
partner_invoice_id = fields.Many2one(tracking=True)
pricelist_id = fields.Many2one(tracking=True)
payment_term_id = fields.Many2one(tracking=True)
fiscal_position_id = fields.Many2one(tracking=True)
# for reports
has_discount = fields.Boolean(compute='_compute_has_discount')
@api.depends('order_line.discount')
def _compute_has_discount(self):
prec = self.env['decimal.precision'].precision_get('Discount')
for order in self:
has_discount = False
for line in order.order_line:
if not line.display_type and not float_is_zero(
line.discount, precision_digits=prec):
has_discount = True
break
order.has_discount = has_discount
# for report
def py3o_lines_layout(self):
self.ensure_one()
res = []
has_sections = False
subtotal = 0.0
for line in self.order_line:
if line.display_type == 'line_section':
# insert line
if has_sections:
res.append({'subtotal': subtotal})
subtotal = 0.0 # reset counter
has_sections = True
else:
if not line.display_type:
subtotal += line.price_subtotal
res.append({'line': line})
if has_sections: # insert last subtotal line
res.append({'subtotal': subtotal})
# res:
# [
# {'line': sale_order_line(1) with display_type=='line_section'},
# {'line': sale_order_line(2) without display_type},
# {'line': sale_order_line(3) without display_type},
# {'line': sale_order_line(4) with display_type=='line_note'},
# {'subtotal': 8932.23},
# ]
return res
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
@api.onchange('product_uom', 'product_uom_qty')
def product_uom_change(self):
# When the user has manually set a custom price
# he is often upset when Odoo changes it when he changes the qty
# So we add a warning in which we recall the old price.
res = {}
old_price = self.price_unit
super().product_uom_change()
new_price = self.price_unit
prec = self.env['decimal.precision'].precision_get('Product Price')
if float_compare(old_price, new_price, precision_digits=prec):
pricelist = self.order_id.pricelist_id
res['warning'] = {
'title': _('Price updated'),
'message': _(
"Due to the update of the ordered quantity on line '%s', "
"the price has been updated according to pricelist %s.\n"
"Old price: %s\n"
"New price: %s") % (
self.name,
pricelist.display_name,
formatLang(
self.env, old_price, currency_obj=pricelist.currency_id),
formatLang(
self.env, new_price, currency_obj=pricelist.currency_id))
}
return res

View File

@@ -1,14 +0,0 @@
# Copyright 2017-2019 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
class ProductTemplate(models.Model):
_inherit = 'product.template'
service_type = fields.Selection(track_visibility='onchange')
expense_policy = fields.Selection(track_visibility='onchange')
invoice_policy = fields.Selection(track_visibility='onchange')
sale_line_warn = fields.Selection(track_visibility='onchange')

View File

@@ -1,65 +0,0 @@
# Copyright (C) 2015-2019 Akretion France (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
from odoo.tools import float_is_zero
class SaleOrder(models.Model):
_inherit = 'sale.order'
date_order = fields.Datetime(track_visibility='onchange')
confirmation_date = fields.Datetime(track_visibility='onchange')
client_order_ref = fields.Char(track_visibility='onchange')
# for partner_id, the 'sale' module sets track_visibility='always'
partner_id = fields.Many2one(track_visibility='onchange')
amount_tax = fields.Monetary(track_visibility='onchange')
partner_shipping_id = fields.Many2one(track_visibility='onchange')
partner_invoice_id = fields.Many2one(track_visibility='onchange')
pricelist_id = fields.Many2one(track_visibility='onchange')
payment_term_id = fields.Many2one(track_visibility='onchange')
fiscal_position_id = fields.Many2one(track_visibility='onchange')
# for reports
has_discount = fields.Boolean(
compute='_compute_has_discount', readonly=True)
@api.depends('order_line.discount')
def _compute_has_discount(self):
prec = self.env['decimal.precision'].precision_get('Discount')
for order in self:
has_discount = False
for line in order.order_line:
if not float_is_zero(line.discount, precision_digits=prec):
has_discount = True
break
order.has_discount = has_discount
# for report
def py3o_lines_layout(self):
self.ensure_one()
res = []
has_sections = False
subtotal = 0.0
for line in self.order_line:
if line.display_type == 'line_section':
# insert line
if has_sections:
res.append({'subtotal': subtotal})
subtotal = 0.0 # reset counter
has_sections = True
else:
if not line.display_type:
subtotal += line.price_subtotal
res.append({'line': line})
if has_sections: # insert last subtotal line
res.append({'subtotal': subtotal})
# res:
# [
# {'line': sale_order_line(1) with display_type=='line_section'},
# {'line': sale_order_line(2) without display_type},
# {'line': sale_order_line(3) without display_type},
# {'line': sale_order_line(4) with display_type=='line_note'},
# {'subtotal': 8932.23},
# ]
return res

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2019 Akretion France (http://www.akretion.com/)
Copyright 2019-2020 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!--
<record id="account_invoice_form" model="ir.ui.view">
<field name="name">sale_usability.customer.invoice.form</field>
<field name="model">account.invoice</field>
@@ -24,14 +24,15 @@
</div>
</field>
</record>
-->
<record id="account_invoice_line_form" model="ir.ui.view">
<field name="name">sale_usability.invoice.line.form</field>
<field name="model">account.invoice.line</field>
<field name="inherit_id" ref="sale.account_invoice_line_form"/>
<record id="view_move_form" model="ir.ui.view">
<field name="name">sale_usability.account.move.form</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@groups='analytic.group_analytic_tags']" position="after">
<field name="sale_line_ids" widget="many2many_tags" attrs="{'invisible': [('invoice_type', 'in', ('in_invoice', 'in_refund'))]}"/>
<xpath expr="//field[@name='invoice_line_ids']/form//field[@name='analytic_account_id']" position="after">
<field name="sale_line_ids" widget="many2many_tags" attrs="{'invisible': [('sale_line_ids', '=', [])]}"/>
</xpath>
</field>
</record>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2015-2020 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<!-- Add a 'Product Category' menu entry under Sales > Configuration > Products,
similar to what we have in Stock > Configuration > Products
because we need this menu entry even if the 'stock' module is not installed -->
<menuitem id="product_category_sale_menu" action="product.product_category_action_form"
parent="sale.prod_config_main" sequence="10"/>
</odoo>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (http://www.akretion.com/)
Copyright 2017-2020 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
@@ -20,7 +20,7 @@ because the parent menu entry is in the sale module -->
<menuitem id="product_pricelist_item_menu"
parent="sale.product_menu_catalog"
action="product_pricelist_item_action"
groups="product.group_pricelist_item"
groups="product.group_sale_pricelist"
sequence="50"/>

View File

@@ -23,7 +23,7 @@
</button>
<!-- client_order_ref is an important field, so we should put it in the top like in v8, not hidden in the second tab -->
<field name="client_order_ref" position="replace"/>
<field name="confirmation_date" position="after">
<field name="date_order" position="after">
<field name="client_order_ref"/>
</field>
</field>
@@ -34,8 +34,8 @@
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_quotation_tree"/>
<field name="arch" type="xml">
<field name="amount_total" position="before">
<field name="amount_untaxed" sum="Total Untaxed"/>
<field name="amount_untaxed" position="attributes">
<attribute name="optional">show</attribute>
</field>
</field>
</record>
@@ -45,8 +45,8 @@
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree"/>
<field name="arch" type="xml">
<field name="amount_total" position="before">
<field name="amount_untaxed" sum="Total Untaxed"/>
<field name="amount_untaxed" position="attributes">
<attribute name="optional">show</attribute>
</field>
<field name="state" position="attributes">
<attribute name="invisible">0</attribute>
@@ -60,7 +60,6 @@
<field name="inherit_id" ref="sale.view_sales_order_filter"/>
<field name="arch" type="xml">
<filter name="order_month" position="after">
<filter string="Order Confirmation Month" name="confirmation_date_groupby" context="{'group_by': 'confirmation_date'}"/>
<filter string="State" name="state_groupby" context="{'group_by': 'state'}"/>
</filter>
</field>
@@ -111,10 +110,4 @@ https://github.com/odoo/odoo/commit/c1e5ab9b1331c3cb7dc2232bf78952bdb40ad939 -->
</field>
</record>
<!-- Add a 'Product Category' menu entry under Sales > Configuration > Products,
similar to what we have in Stock > Configuration > Products
because we need this menu entry even if the 'stock' module is not installed -->
<menuitem id="product_category_sale_menu" action="product.product_category_action_form"
parent="sale.prod_config_main" sequence="10"/>
</odoo>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2018-2019 Akretion (http://www.akretion.com/)
Copyright 2018-2020 Akretion (http://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
@@ -43,4 +43,15 @@
</field>
</record>
<record id="view_order_product_search" model="ir.ui.view">
<field name="name">usability.sale.report.search</field>
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.view_order_product_search"/>
<field name="arch" type="xml">
<field name="user_id" position="after">
<field name="analytic_account_id" groups="analytic.group_analytic_accounting"/>
</field>
</field>
</record>
</odoo>