[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

@@ -2,45 +2,53 @@
# @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 datetime import datetime
import logging
from datetime import datetime
from odoo import api, fields, models
logger = logging.getLogger(__name__)
class ProcurementGroup(models.Model):
_inherit = 'procurement.group'
_inherit = "procurement.group"
picking_ids = fields.One2many(
'stock.picking', 'group_id', string='Pickings', readonly=True)
"stock.picking", "group_id", string="Pickings", readonly=True
)
@api.model
def run_scheduler(self, use_new_cursor=False, company_id=False):
'''Inherit to add info logs'''
"""Inherit to add info logs"""
logger.info(
'START procurement scheduler '
'(company ID=%d, uid=%d, use_new_cursor=%s)',
company_id, self._uid, use_new_cursor)
"START procurement scheduler " "(company ID=%d, uid=%d, use_new_cursor=%s)",
company_id,
self._uid,
use_new_cursor,
)
start_datetime = datetime.now()
res = super().run_scheduler(
use_new_cursor=use_new_cursor, company_id=company_id)
use_new_cursor=use_new_cursor, company_id=company_id
)
logger.info(
'END procurement scheduler '
'(company ID=%d, uid=%d, use_new_cursor=%s)',
company_id, self._uid, use_new_cursor)
"END procurement scheduler " "(company ID=%d, uid=%d, use_new_cursor=%s)",
company_id,
self._uid,
use_new_cursor,
)
try:
# I put it in a try/except, to be sure that, even if the user
# the execute the scheduler doesn't have create right on
# procurement.scheduler.log
self.env['procurement.scheduler.log'].create({
'company_id': company_id,
'start_datetime': start_datetime,
})
self.env["procurement.scheduler.log"].create(
{
"company_id": company_id,
"start_datetime": start_datetime,
}
)
# If I don't do an explicit cr.commit(), it doesn't create
# the procurement.scheduler.log... I don't know why
self._cr.commit()
except Exception as e:
logger.warning(
'Could not create procurement.scheduler.log (error: %s)', e)
logger.warning("Could not create procurement.scheduler.log (error: %s)", e)
return res

View File

@@ -6,10 +6,9 @@ from odoo import fields, models
class ProcurementSchedulerLog(models.Model):
_name = 'procurement.scheduler.log'
_description = 'Logs of the Procurement Scheduler'
_order = 'create_date desc'
_name = "procurement.scheduler.log"
_description = "Logs of the Procurement Scheduler"
_order = "create_date desc"
company_id = fields.Many2one(
'res.company', string='Company', readonly=True)
start_datetime = fields.Datetime(string='Start Date', readonly=True)
company_id = fields.Many2one("res.company", string="Company", readonly=True)
start_datetime = fields.Datetime(string="Start Date", readonly=True)

View File

@@ -6,26 +6,26 @@ from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
_inherit = "product.template"
tracking = fields.Selection(tracking=True)
sale_delay = fields.Float(tracking=True)
# the 'stock' module adds 'product' in type...
# but forgets to make it the default
type = fields.Selection(default='product')
type = fields.Selection(default="product")
def action_view_stock_move(self):
action = self.env.ref('stock.stock_move_action').sudo().read()[0]
action['domain'] = [('product_id.product_tmpl_id', 'in', self.ids)]
action['context'] = {'search_default_done': True}
action = self.env.ref("stock.stock_move_action").sudo().read()[0]
action["domain"] = [("product_id.product_tmpl_id", "in", self.ids)]
action["context"] = {"search_default_done": True}
return action
class ProductProduct(models.Model):
_inherit = 'product.product'
_inherit = "product.product"
def action_view_stock_move(self):
action = self.env.ref('stock.stock_move_action').sudo().read()[0]
action['domain'] = [('product_id', 'in', self.ids)]
action['context'] = {'search_default_done': True}
action = self.env.ref("stock.stock_move_action").sudo().read()[0]
action["domain"] = [("product_id", "in", self.ids)]
action["context"] = {"search_default_done": True}
return action

View File

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

View File

@@ -2,44 +2,66 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models, _
from odoo import _, fields, models
from odoo.tools import float_compare, float_is_zero
class StockInventory(models.Model):
_inherit = 'stock.inventory'
_inherit = "stock.inventory"
prefill_counted_quantity = fields.Selection(
readonly=True, states={'draft': [('readonly', False)]})
readonly=True, states={"draft": [("readonly", False)]}
)
class StockInventoryLine(models.Model):
_inherit = 'stock.inventory.line'
_inherit = "stock.inventory.line"
product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode")
product_barcode = fields.Char(
related="product_id.barcode", string="Product Barcode"
)
difference_qty = fields.Float(search="_search_difference_qty_usability")
def _search_difference_qty_usability(self, operator, value):
# Inspired by the method _search_difference_qty() from the
# official stock module
# So a part of this code is copyright Odoo SA under LGPL licence
if not self.env.context.get('default_inventory_id'):
raise NotImplementedError(_('Unsupported search on %s outside of an Inventory Adjustment', 'difference_qty'))
lines = self.search([('inventory_id', '=', self.env.context.get('default_inventory_id'))])
if not self.env.context.get("default_inventory_id"):
raise NotImplementedError(
_(
"Unsupported search on %s outside of an Inventory Adjustment",
"difference_qty",
)
)
lines = self.search(
[("inventory_id", "=", self.env.context.get("default_inventory_id"))]
)
line_ids = []
for line in lines:
if operator == '=':
if operator == "=":
if float_is_zero(line.difference_qty, line.product_id.uom_id.rounding):
line_ids.append(line.id)
elif operator == '!=':
if not float_is_zero(line.difference_qty, line.product_id.uom_id.rounding):
elif operator == "!=":
if not float_is_zero(
line.difference_qty, line.product_id.uom_id.rounding
):
line_ids.append(line.id)
elif operator == '>':
if float_compare(line.difference_qty, 0, line.product_id.uom_id.rounding) > 0:
elif operator == ">":
if (
float_compare(
line.difference_qty, 0, line.product_id.uom_id.rounding
)
> 0
):
line_ids.append(line.id)
elif operator == '<':
if float_compare(line.difference_qty, 0, line.product_id.uom_id.rounding) < 0:
elif operator == "<":
if (
float_compare(
line.difference_qty, 0, line.product_id.uom_id.rounding
)
< 0
):
line_ids.append(line.id)
else:
raise NotImplementedError()
return [('id', 'in', line_ids)]
return [("id", "in", line_ids)]

View File

@@ -6,6 +6,6 @@ from odoo import fields, models
class StockLocationRoute(models.Model):
_inherit = 'stock.location.route'
_inherit = "stock.location.route"
name = fields.Char(translate=False)

View File

@@ -2,37 +2,40 @@
# @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, _
from odoo.exceptions import UserError
import logging
from odoo import _, fields, models
from odoo.exceptions import UserError
logger = logging.getLogger(__name__)
class StockMove(models.Model):
_inherit = 'stock.move'
_inherit = "stock.move"
# for optional display in tree view
product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode")
product_barcode = fields.Char(
related="product_id.barcode", string="Product Barcode"
)
# def name_get(self):
# '''name_get of stock_move is important for the reservation of the
# quants: so want to add the name of the customer and the expected date
# in it'''
# res = []
# for line in self:
# name = '%s > %s' % (
# line.location_id.name, line.location_dest_id.name)
# if line.product_id.code:
# name = '%s: %s' % (line.product_id.code, name)
# if line.picking_id.origin:
# name = '%s %s' % (line.picking_id.origin, name)
# if line.partner_id:
# name = '%s %s' % (line.partner_id.name, name)
# if line.date_expected:
# name = '%s %s' % (name, line.date_expected)
# res.append((line.id, name))
# return res
# def name_get(self):
# '''name_get of stock_move is important for the reservation of the
# quants: so want to add the name of the customer and the expected date
# in it'''
# res = []
# for line in self:
# name = '%s > %s' % (
# line.location_id.name, line.location_dest_id.name)
# if line.product_id.code:
# name = '%s: %s' % (line.product_id.code, name)
# if line.picking_id.origin:
# name = '%s %s' % (line.picking_id.origin, name)
# if line.partner_id:
# name = '%s %s' % (line.partner_id.name, name)
# if line.date_expected:
# name = '%s %s' % (name, line.date_expected)
# res.append((line.id, name))
# return res
def button_do_unreserve(self):
for move in self:
@@ -40,37 +43,52 @@ class StockMove(models.Model):
picking = move.picking_id
if picking:
product = move.product_id
picking.message_post(body=_(
"Product <a href=# data-oe-model=product.product "
"data-oe-id=%d>%s</a> qty %s %s <b>unreserved</b>")
% (product.id, product.display_name,
move.product_qty, product.uom_id.name))
picking.message_post(
body=_(
"Product <a href=# data-oe-model=product.product "
"data-oe-id=%d>%s</a> qty %s %s <b>unreserved</b>"
)
% (
product.id,
product.display_name,
move.product_qty,
product.uom_id.name,
)
)
# Copied from do_unreserved of stock.picking
picking.package_level_ids.filtered(lambda p: not p.move_ids).unlink()
class StockMoveLine(models.Model):
_inherit = 'stock.move.line'
_inherit = "stock.move.line"
# for optional display in tree view
product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode")
product_barcode = fields.Char(
related="product_id.barcode", string="Product Barcode"
)
# TODO: I think it's not complete
def button_do_unreserve(self):
for moveline in self:
if moveline.state == 'cancel':
if moveline.state == "cancel":
continue
elif moveline.state == 'done':
raise UserError(_(
"You cannot unreserve a move line in done state."))
elif moveline.state == "done":
raise UserError(_("You cannot unreserve a move line in done state."))
picking = moveline.move_id.picking_id
if picking:
product = moveline.product_id
picking.message_post(body=_(
"Product <a href=# data-oe-model=product.product "
"data-oe-id=%d>%s</a> qty %s %s <b>unreserved</b>")
% (product.id, product.display_name,
moveline.product_qty, product.uom_id.name))
picking.message_post(
body=_(
"Product <a href=# data-oe-model=product.product "
"data-oe-id=%d>%s</a> qty %s %s <b>unreserved</b>"
)
% (
product.id,
product.display_name,
moveline.product_qty,
product.uom_id.name,
)
)
# Copied from do_unreserved of stock.picking
picking.package_level_ids.filtered(lambda p: not p.move_ids).unlink()
moveline.unlink()

View File

@@ -2,15 +2,16 @@
# @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, _
import logging
from odoo import _, fields, models
logger = logging.getLogger(__name__)
class StockPicking(models.Model):
_inherit = 'stock.picking'
# _order = 'id desc'
_inherit = "stock.picking"
# _order = 'id desc'
# In the stock module: _order = "priority desc, scheduled_date asc, id desc"
# The problem is date asc
@@ -27,6 +28,6 @@ class StockPicking(models.Model):
class StockPickingType(models.Model):
_inherit = 'stock.picking.type'
_inherit = "stock.picking.type"
name = fields.Char(translate=False)

View File

@@ -6,12 +6,14 @@ from odoo import fields, models
class StockQuant(models.Model):
_inherit = 'stock.quant'
_inherit = "stock.quant"
product_barcode = fields.Char(related='product_id.barcode', string="Product Barcode")
product_barcode = fields.Char(
related="product_id.barcode", string="Product Barcode"
)
def action_stock_move_lines_reserved(self):
self.ensure_one()
action = self.action_view_stock_moves()
action['context'] = {'search_default_todo': True}
action["context"] = {"search_default_todo": True}
return action

View File

@@ -2,27 +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, models
import logging
from odoo import api, models
logger = logging.getLogger(__name__)
class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'
_inherit = "stock.warehouse.orderpoint"
@api.model
def _procure_orderpoint_confirm(
self, use_new_cursor=False, company_id=False, raise_user_error=True):
logger.info(
'procurement scheduler: START to create moves from '
'orderpoints')
self, use_new_cursor=False, company_id=False, raise_user_error=True
):
logger.info("procurement scheduler: START to create moves from " "orderpoints")
res = super()._procure_orderpoint_confirm(
use_new_cursor=use_new_cursor, company_id=company_id,
raise_user_error=raise_user_error)
logger.info(
'procurement scheduler: END creation of moves from '
'orderpoints')
use_new_cursor=use_new_cursor,
company_id=company_id,
raise_user_error=raise_user_error,
)
logger.info("procurement scheduler: END creation of moves from " "orderpoints")
return res
# This is for the button shortcut "reordering rules" on
@@ -30,9 +30,10 @@ class StockWarehouseOrderpoint(models.Model):
# good value, not the default stock location of the first WH of the company
@api.model
def default_get(self, fields_list):
if self._context.get('default_location_id'):
location = self.env['stock.location'].browse(
self._context['default_location_id'])
if self._context.get("default_location_id"):
location = self.env["stock.location"].browse(
self._context["default_location_id"]
)
wh = location.get_warehouse()
if location and wh:
self = self.with_context(default_warehouse_id=wh.id)
@@ -42,9 +43,11 @@ class StockWarehouseOrderpoint(models.Model):
# but I think it's not very useful to have such an "active" field
# on orderpoints ; when you think the order point is bad, you update
# the min/max values, you don't de-active it !
_sql_constraints = [(
'company_wh_location_product_unique',
'unique(company_id, warehouse_id, location_id, product_id)',
'An orderpoint already exists for the same company, same warehouse, '
'same stock location and same product.'
)]
_sql_constraints = [
(
"company_wh_location_product_unique",
"unique(company_id, warehouse_id, location_id, product_id)",
"An orderpoint already exists for the same company, same warehouse, "
"same stock location and same product.",
)
]