Initialize v18 branch

Rename *_usability modules to *_usability_akretion
This commit is contained in:
Alexis de Lattre
2024-12-24 10:11:21 +01:00
parent 9913924202
commit 13744fc404
264 changed files with 50 additions and 87 deletions

View File

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

View File

@@ -0,0 +1,52 @@
# Copyright 2015-2022 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).
from odoo import models
from collections import OrderedDict
class AccountMove(models.Model):
_inherit = 'account.move'
def py3o_lines_layout_groupby_order(self, subtotal=True):
# This method is an alternative to the method py3o_lines_layout()
# defined above: you just have to change the call in the invoice
# ODT template
self.ensure_one()
res1 = OrderedDict()
# {categ(1): {'lines': [l1, l2], 'subtotal': 23.32}}
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
if order in res1:
res1[order]['lines'].append(line)
res1[order]['subtotal'] += line.price_subtotal
else:
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})
else:
for order, ldict in res1.items():
res2.append({'categ': order})
for line in ldict['lines']:
res2.append({'line': line})
if subtotal:
res2.append({'subtotal': ldict['subtotal']})
# res2:
# [
# {'categ': categ(1)},
# {'line': invoice_line(2)},
# {'line': invoice_line(3)},
# {'subtotal': 8932.23},
# ]
# pprint(res2)
return res2

View File

@@ -0,0 +1,15 @@
# Copyright 2017-2022 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)
expense_policy = fields.Selection(tracking=True)

View File

@@ -0,0 +1,13 @@
# Copyright 2021-2022 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 fields, models
class ResCompany(models.Model):
_inherit = 'res.company'
# Similar to the field static_invoice_terms in account_usability
static_sale_terms = fields.Text(
translate=True, string="Legal Terms on Quotation")

View File

@@ -0,0 +1,11 @@
# Copyright 2017-2022 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 fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
sale_warn = fields.Selection(tracking=True)

View File

@@ -0,0 +1,135 @@
# 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
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)
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_attachment = fields.Boolean(
compute='_compute_has_attachment',
search='_search_has_attachment')
@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
def _compute_has_attachment(self):
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)]):
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'])
for att in search_res:
att_order_ids[att['res_id']] = True
res = [('id', value and 'in' or 'not in', list(att_order_ids))]
return res
# 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
elif 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'
# for optional display in tree view
product_barcode = fields.Char(
related='product_id.barcode', string="Product Barcode")
# @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
def _get_sale_order_line_multiline_description_sale(self):
# This is useful when you want to have the product code in a dedicated
# column in your sale order report
# The same ir.config_parameter is used in sale_usability,
# purchase_usability and account_usability
no_product_code_param = self.env['ir.config_parameter'].sudo().get_param(
'usability.line_name_no_product_code')
if no_product_code_param and no_product_code_param == 'True':
self = self.with_context(display_default_code=False)
return super()._get_sale_order_line_multiline_description_sale()