[IMP] pre-commit: first run on whole repo

This commit is contained in:
Kevin Khao
2021-11-26 18:54:38 +03:00
parent a04b8980e1
commit 167aefee13
289 changed files with 6020 additions and 4170 deletions

View File

@@ -3,23 +3,23 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Sale Usability',
'version': '14.0.1.0.0',
'category': 'Sales',
'license': 'AGPL-3',
'summary': 'Usability improvements on sale module',
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': [
'sale',
'base_view_inheritance_extension',
],
'data': [
'views/sale_order.xml',
'views/product_category.xml',
'views/sale_report.xml',
'views/product_pricelist_item.xml',
'views/account_move.xml',
],
'installable': True,
"name": "Sale Usability",
"version": "14.0.1.0.0",
"category": "Sales",
"license": "AGPL-3",
"summary": "Usability improvements on sale module",
"author": "Akretion",
"website": "https://github.com/OCA/odoo-usability",
"depends": [
"sale",
"base_view_inheritance_extension",
],
"data": [
"views/sale_order.xml",
"views/product_category.xml",
"views/sale_report.xml",
"views/product_pricelist_item.xml",
"views/account_move.xml",
],
"installable": True,
}

View File

@@ -2,25 +2,27 @@
# @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 collections import OrderedDict
from odoo import api, fields, models
class AccountMove(models.Model):
_inherit = 'account.move'
_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")
sale_count = fields.Integer(
string='Sale Order Count', compute='_compute_sale_ids')
"sale.order", string="Sale Orders", compute="_compute_sale_ids"
)
sale_count = fields.Integer(string="Sale Order Count", compute="_compute_sale_ids")
@api.depends('invoice_line_ids.sale_line_ids')
@api.depends("invoice_line_ids.sale_line_ids")
def _compute_sale_ids(self):
for invoice in self:
if invoice.move_type == 'out_invoice':
sales = invoice.invoice_line_ids.mapped('sale_line_ids').\
mapped('order_id')
if invoice.move_type == "out_invoice":
sales = invoice.invoice_line_ids.mapped("sale_line_ids").mapped(
"order_id"
)
invoice.sale_ids = sales.ids
invoice.sale_count = len(sales.ids)
else:
@@ -29,16 +31,18 @@ class AccountMove(models.Model):
def show_sale_orders(self):
self.ensure_one()
action = self.env.ref('sale.action_orders').read()[0]
action = self.env.ref("sale.action_orders").read()[0]
sales = self.sale_ids
if len(sales) > 1:
action['domain'] = [('id', 'in', sales.ids)]
action["domain"] = [("id", "in", sales.ids)]
else:
action.update({
'res_id': sales.id,
'view_mode': 'form,tree,kanban,calendar,pivot,graph,activity',
'views': False,
})
action.update(
{
"res_id": sales.id,
"view_mode": "form,tree,kanban,calendar,pivot,graph,activity",
"views": False,
}
)
return action
def py3o_lines_layout_groupby_order(self, subtotal=True):
@@ -48,31 +52,33 @@ class AccountMove(models.Model):
self.ensure_one()
res1 = OrderedDict()
# {categ(1): {'lines': [l1, l2], 'subtotal': 23.32}}
soo = self.env['sale.order']
soo = self.env["sale.order"]
for line in self.invoice_line_ids:
order = not line.display_type and 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
res1[order]["lines"].append(line)
res1[order]["subtotal"] += line.price_subtotal
else:
res1[order] = {
'lines': [line],
'subtotal': line.price_subtotal}
res1[order] = {"lines": [line], "subtotal": line.price_subtotal}
# from pprint import pprint
# pprint(res1)
res2 = []
if len(res1) == 1 and not list(res1)[0]:
# No order at all
for line in list(res1.values())[0]['lines']:
res2.append({'line': line})
for line in list(res1.values())[0]["lines"]:
res2.append({"line": line})
else:
for order, ldict in res1.items():
res2.append({'categ': order})
for line in ldict['lines']:
res2.append({'line': line})
res2.append({"categ": order})
for line in ldict["lines"]:
res2.append({"line": line})
if subtotal:
res2.append({'subtotal': ldict['subtotal']})
res2.append({"subtotal": ldict["subtotal"]})
# res2:
# [
# {'categ': categ(1)},

View File

@@ -6,7 +6,7 @@ from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
_inherit = "product.template"
service_type = fields.Selection(tracking=True)
expense_policy = fields.Selection(tracking=True)

View File

@@ -6,6 +6,6 @@ from odoo import fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
_inherit = "res.partner"
sale_warn = fields.Selection(tracking=True)

View File

@@ -2,13 +2,13 @@
# @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 import _, api, fields, models
from odoo.tools import float_compare, float_is_zero
from odoo.tools.misc import formatLang
class SaleOrder(models.Model):
_inherit = 'sale.order'
_inherit = "sale.order"
date_order = fields.Datetime(tracking=True)
client_order_ref = fields.Char(tracking=True)
@@ -20,45 +20,53 @@ class SaleOrder(models.Model):
payment_term_id = fields.Many2one(tracking=True)
fiscal_position_id = fields.Many2one(tracking=True)
# for reports
has_discount = fields.Boolean(compute='_compute_has_discount')
has_discount = fields.Boolean(compute="_compute_has_discount")
has_attachment = fields.Boolean(
compute='_compute_has_attachment',
search='_search_has_attachment')
compute="_compute_has_attachment", search="_search_has_attachment"
)
@api.depends('order_line.discount')
@api.depends("order_line.discount")
def _compute_has_discount(self):
prec = self.env['decimal.precision'].precision_get('Discount')
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):
line.discount, precision_digits=prec
):
has_discount = True
break
order.has_discount = has_discount
def _compute_has_attachment(self):
iao = self.env['ir.attachment']
iao = self.env["ir.attachment"]
for order in self:
if iao.search_count([
('res_model', '=', 'sale.order'),
('res_id', '=', order.id),
('type', '=', 'binary'),
('company_id', '=', order.company_id.id)]):
if iao.search_count(
[
("res_model", "=", "sale.order"),
("res_id", "=", order.id),
("type", "=", "binary"),
("company_id", "=", order.company_id.id),
]
):
order.has_attachment = True
else:
order.has_attachment = False
def _search_has_attachment(self, operator, value):
att_order_ids = {}
if operator == '=':
search_res = self.env['ir.attachment'].search_read([
('res_model', '=', 'sale.order'),
('type', '=', 'binary'),
('res_id', '!=', False)], ['res_id'])
if operator == "=":
search_res = self.env["ir.attachment"].search_read(
[
("res_model", "=", "sale.order"),
("type", "=", "binary"),
("res_id", "!=", False),
],
["res_id"],
)
for att in search_res:
att_order_ids[att['res_id']] = True
res = [('id', value and 'in' or 'not in', list(att_order_ids))]
att_order_ids[att["res_id"]] = True
res = [("id", value and "in" or "not in", list(att_order_ids))]
return res
# for report
@@ -68,17 +76,17 @@ class SaleOrder(models.Model):
has_sections = False
subtotal = 0.0
for line in self.order_line:
if line.display_type == 'line_section':
if line.display_type == "line_section":
# insert line
if has_sections:
res.append({'subtotal': subtotal})
res.append({"subtotal": subtotal})
subtotal = 0.0 # reset counter
has_sections = True
elif not line.display_type:
subtotal += line.price_subtotal
res.append({'line': line})
res.append({"line": line})
if has_sections: # insert last subtotal line
res.append({'subtotal': subtotal})
res.append({"subtotal": subtotal})
# res:
# [
# {'line': sale_order_line(1) with display_type=='line_section'},
@@ -91,13 +99,14 @@ class SaleOrder(models.Model):
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
_inherit = "sale.order.line"
# for optional display in tree view
product_barcode = fields.Char(
related='product_id.barcode', string="Product Barcode")
related="product_id.barcode", string="Product Barcode"
)
@api.onchange('product_uom', 'product_uom_qty')
@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
@@ -106,21 +115,22 @@ class SaleOrderLine(models.Model):
old_price = self.price_unit
super().product_uom_change()
new_price = self.price_unit
prec = self.env['decimal.precision'].precision_get('Product Price')
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': _(
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))
}
"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,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
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">
@@ -15,11 +14,12 @@
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
name="show_sale_orders"
type="object"
class="oe_stat_button"
icon="fa-pencil-square-o"
attrs="{'invisible': [('sale_count', '=', 0)]}">
name="show_sale_orders"
type="object"
class="oe_stat_button"
icon="fa-pencil-square-o"
attrs="{'invisible': [('sale_count', '=', 0)]}"
>
<field name="sale_count" widget="statinfo" string="Sale Orders" />
</button>
</div>
@@ -29,10 +29,17 @@
<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="inherit_id" ref="account.view_move_form" />
<field name="arch" type="xml">
<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
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

@@ -1,16 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<?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"/>
<menuitem
id="product_category_sale_menu"
action="product.product_category_action_form"
parent="sale.prod_config_main"
sequence="10"
/>
</odoo>

View File

@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
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).
-->
<odoo>
<!-- This is in the sale_usability module instead of the product_usability module
@@ -17,11 +16,13 @@ because the parent menu entry is in the sale module -->
</record>
<!-- This menu entry is very useful for mass export/import of prices -->
<menuitem id="product_pricelist_item_menu"
parent="sale.product_menu_catalog"
action="product_pricelist_item_action"
groups="product.group_sale_pricelist"
sequence="50"/>
<menuitem
id="product_pricelist_item_menu"
parent="sale.product_menu_catalog"
action="product_pricelist_item_action"
groups="product.group_sale_pricelist"
sequence="50"
/>
</odoo>

View File

@@ -1,36 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 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).
-->
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">usability.sale.order.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<field name="fiscal_position_id" position="attributes">
<attribute name="widget">selection</attribute>
</field>
<field name="partner_shipping_id" position="attributes">
<attribute name="context" operation="python_dict" key="show_address">1</attribute>
<attribute
name="context"
operation="python_dict"
key="show_address"
>1</attribute>
</field>
<button name="action_cancel" type="object" position="attributes">
<attribute name="confirm">Are you sure you want to cancel this sale order?</attribute>
<attribute
name="confirm"
>Are you sure you want to cancel this sale order?</attribute>
</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="client_order_ref" position="replace" />
<field name="date_order" position="after">
<field name="client_order_ref"/>
<field name="client_order_ref" />
</field>
<button name="action_quotation_send" states="sent,sale" position="after">
<button name="%(sale.action_report_saleorder)d" type="action" string="Print" states="draft,sent,sale,done"/>
<button
name="%(sale.action_report_saleorder)d"
type="action"
string="Print"
states="draft,sent,sale,done"
/>
</button>
<xpath expr="//field[@name='order_line']/tree/field[@name='product_template_id']" position="after">
<field name="product_barcode" optional="hide"/>
<xpath
expr="//field[@name='order_line']/tree/field[@name='product_template_id']"
position="after"
>
<field name="product_barcode" optional="hide" />
</xpath>
</field>
</record>
@@ -38,7 +51,7 @@
<record id="view_quotation_tree" model="ir.ui.view">
<field name="name">usability.sale.quotation.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_quotation_tree"/>
<field name="inherit_id" ref="sale.view_quotation_tree" />
<field name="arch" type="xml">
<field name="amount_untaxed" position="attributes">
<attribute name="optional">show</attribute>
@@ -49,7 +62,7 @@
<record id="view_order_tree" model="ir.ui.view">
<field name="name">usability.sale.order.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree"/>
<field name="inherit_id" ref="sale.view_order_tree" />
<field name="arch" type="xml">
<field name="amount_untaxed" position="attributes">
<attribute name="optional">show</attribute>
@@ -63,14 +76,22 @@
<record id="view_sales_order_filter" model="ir.ui.view">
<field name="name">usability.sale.order.search</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_sales_order_filter"/>
<field name="inherit_id" ref="sale.view_sales_order_filter" />
<field name="arch" type="xml">
<filter name="order_month" position="after">
<filter string="State" name="state_groupby" context="{'group_by': 'state'}"/>
<filter
string="State"
name="state_groupby"
context="{'group_by': 'state'}"
/>
</filter>
<filter name="activities_upcoming_all" position="after">
<separator/>
<filter name="no_attachment" string="Missing Attachment" domain="[('has_attachment', '=', False)]"/>
<separator />
<filter
name="no_attachment"
string="Missing Attachment"
domain="[('has_attachment', '=', False)]"
/>
</filter>
</field>
</record>
@@ -92,10 +113,14 @@ https://github.com/odoo/odoo/commit/c1e5ab9b1331c3cb7dc2232bf78952bdb40ad939 -->
<record id="view_sales_order_line_filter" model="ir.ui.view">
<field name="name">usability.sale.order.line.search</field>
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_sales_order_line_filter"/>
<field name="inherit_id" ref="sale.view_sales_order_line_filter" />
<field name="arch" type="xml">
<filter name="product" position="before">
<filter string="Customer" name="partner_groupby" context="{'group_by': 'order_partner_id'}"/>
<filter
string="Customer"
name="partner_groupby"
context="{'group_by': 'order_partner_id'}"
/>
</filter>
</field>
</record>
@@ -103,7 +128,7 @@ https://github.com/odoo/odoo/commit/c1e5ab9b1331c3cb7dc2232bf78952bdb40ad939 -->
<record id="view_order_line_tree" model="ir.ui.view">
<field name="name">usability.sale.order.line.tree</field>
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_order_line_tree"/>
<field name="inherit_id" ref="sale.view_order_line_tree" />
<field name="arch" type="xml">
<field name="product_uom_qty" position="attributes">
<attribute name="sum">1</attribute>

View File

@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
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).
-->
<odoo>
@@ -13,32 +12,34 @@
<field name="model">sale.report</field>
<field name="arch" type="xml">
<tree string="Sales Analysis">
<field name="name"/>
<field name="date"/>
<field name="commercial_partner_id"/>
<field name="user_id"/>
<field name="product_id"/>
<field name="product_uom_qty" sum="1"/>
<field name="qty_delivered" sum="1"/>
<field name="qty_to_invoice" sum="1"/>
<field name="product_uom" groups="uom.group_uom"/>
<field name="price_subtotal" sum="1"/>
<field name="state"/>
<field name="name" />
<field name="date" />
<field name="commercial_partner_id" />
<field name="user_id" />
<field name="product_id" />
<field name="product_uom_qty" sum="1" />
<field name="qty_delivered" sum="1" />
<field name="qty_to_invoice" sum="1" />
<field name="product_uom" groups="uom.group_uom" />
<field name="price_subtotal" sum="1" />
<field name="state" />
</tree>
</field>
</record>
<record id="sale.action_order_report_all" model="ir.actions.act_window">
<field name="context">{'search_default_Sales': 1}</field> <!-- Remove group_by_no_leaf, which breaks tree view -->
<field
name="context"
>{'search_default_Sales': 1}</field> <!-- Remove group_by_no_leaf, which breaks tree view -->
</record>
<record id="view_order_product_pivot" model="ir.ui.view">
<field name="name">usability.sale.report.pivot</field>
<field name="model">sale.report</field>
<field name="inherit_id" ref="sale.view_order_product_pivot"/>
<field name="inherit_id" ref="sale.view_order_product_pivot" />
<field name="arch" type="xml">
<pivot position="attributes">
<attribute name="disable_linking"></attribute>
<attribute name="disable_linking" />
</pivot>
</field>
</record>
@@ -46,10 +47,13 @@
<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="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
name="analytic_account_id"
groups="analytic.group_analytic_accounting"
/>
</field>
</field>
</record>