[MIG] stock_valuation_xlsx from v14 to v16
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright 2020-2021 Akretion France (http://www.akretion.com/)
|
||||
# Copyright 2020-2024 Akretion France (http://www.akretion.com/)
|
||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
@@ -27,9 +27,9 @@ class StockVariationXlsx(models.TransientModel):
|
||||
'stock.warehouse', string='Warehouse', check_company=True,
|
||||
domain="[('company_id', '=', company_id)]")
|
||||
location_id = fields.Many2one(
|
||||
'stock.location', string='Root Stock Location', required=True,
|
||||
domain="[('usage', 'in', ('view', 'internal')), ('company_id', '=', company_id)]",
|
||||
default=lambda self: self._default_location(), check_company=True,
|
||||
'stock.location', string='Root Stock Location', required=True, check_company=True,
|
||||
compute='_compute_location_id', readonly=False, precompute=True, store=True,
|
||||
domain="[('usage', 'in', ('view', 'internal')), ('company_id', 'in', [False, company_id])]",
|
||||
help="The childen locations of the selected locations will "
|
||||
"be taken in the valuation.")
|
||||
categ_ids = fields.Many2many(
|
||||
@@ -56,17 +56,16 @@ class StockVariationXlsx(models.TransientModel):
|
||||
string='Subtotals per Categories', default=True,
|
||||
help="Show a subtotal per product category.")
|
||||
|
||||
@api.model
|
||||
def _default_location(self):
|
||||
wh = self.env.ref('stock.warehouse0')
|
||||
return wh.lot_stock_id
|
||||
@api.depends('warehouse_id', 'company_id')
|
||||
def _compute_location_id(self):
|
||||
for wiz in self:
|
||||
wh = wiz.warehouse_id
|
||||
if not wh:
|
||||
wh = self.env["stock.warehouse"].search([('company_id', '=', wiz.company_id.id)], limit=1)
|
||||
if wh:
|
||||
wiz.location_id = wh.view_location_id.id
|
||||
|
||||
@api.onchange('warehouse_id')
|
||||
def warehouse_id_change(self):
|
||||
if self.warehouse_id:
|
||||
self.location_id = self.warehouse_id.view_location_id.id
|
||||
|
||||
def _check_config(self, company_id):
|
||||
def _check_config(self):
|
||||
self.ensure_one()
|
||||
present = fields.Datetime.now()
|
||||
if self.end_date_type == 'past':
|
||||
@@ -80,7 +79,7 @@ class StockVariationXlsx(models.TransientModel):
|
||||
if self.start_date >= present:
|
||||
raise UserError(_("The start date must be in the past."))
|
||||
cost_method_real_count = self.env['ir.property'].sudo().search([
|
||||
('company_id', '=', company_id),
|
||||
('company_id', '=', self.company_id.id),
|
||||
('name', '=', 'property_cost_method'),
|
||||
('value_text', '=', 'real'),
|
||||
('type', '=', 'selection'),
|
||||
@@ -119,21 +118,21 @@ class StockVariationXlsx(models.TransientModel):
|
||||
domain_quant = [('product_id', 'in', product_ids)] + domain_quant_loc
|
||||
domain_move_in = [('product_id', 'in', product_ids), ('state', '=', 'done')] + domain_move_in_loc
|
||||
domain_move_out = [('product_id', 'in', product_ids), ('state', '=', 'done')] + domain_move_out_loc
|
||||
quants_res = dict((item['product_id'][0], item['quantity']) for item in sqo.read_group(domain_quant, ['product_id', 'quantity'], ['product_id'], orderby='id'))
|
||||
quants_res = dict((item['product_id'][0], item['quantity']) for item in sqo._read_group(domain_quant, ['product_id', 'quantity'], ['product_id'], orderby='id'))
|
||||
domain_move_in_start_to_end = [('date', '>', start_date)] + domain_move_in
|
||||
domain_move_out_start_to_end = [('date', '>', start_date)] + domain_move_out
|
||||
if end_date_type == 'past':
|
||||
|
||||
domain_move_in_end_to_present = [('date', '>', end_date)] + domain_move_in
|
||||
domain_move_out_end_to_present = [('date', '>', end_date)] + domain_move_out
|
||||
moves_in_res_end_to_present = dict((item['product_id'][0], item['product_qty']) for item in smo.read_group(domain_move_in_end_to_present, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
|
||||
moves_out_res_end_to_present = dict((item['product_id'][0], item['product_qty']) for item in smo.read_group(domain_move_out_end_to_present, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
|
||||
moves_in_res_end_to_present = dict((item['product_id'][0], item['product_qty']) for item in smo._read_group(domain_move_in_end_to_present, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
|
||||
moves_out_res_end_to_present = dict((item['product_id'][0], item['product_qty']) for item in smo._read_group(domain_move_out_end_to_present, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
|
||||
|
||||
domain_move_in_start_to_end += [('date', '<', end_date)]
|
||||
domain_move_out_start_to_end += [('date', '<', end_date)]
|
||||
|
||||
moves_in_res_start_to_end = dict((item['product_id'][0], item['product_qty']) for item in smo.read_group(domain_move_in_start_to_end, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
|
||||
moves_out_res_start_to_end = dict((item['product_id'][0], item['product_qty']) for item in smo.read_group(domain_move_out_start_to_end, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
|
||||
moves_in_res_start_to_end = dict((item['product_id'][0], item['product_qty']) for item in smo._read_group(domain_move_in_start_to_end, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
|
||||
moves_out_res_start_to_end = dict((item['product_id'][0], item['product_qty']) for item in smo._read_group(domain_move_out_start_to_end, ['product_id', 'product_qty'], ['product_id'], orderby='id'))
|
||||
|
||||
product_data = {} # key = product_id , value = dict
|
||||
for product in ppo.browse(product_ids):
|
||||
@@ -208,7 +207,7 @@ class StockVariationXlsx(models.TransientModel):
|
||||
company = self.company_id
|
||||
company_id = company.id
|
||||
prec_cur_rounding = company.currency_id.rounding
|
||||
self._check_config(company_id)
|
||||
self._check_config()
|
||||
|
||||
product_ids = self.get_product_ids()
|
||||
if not product_ids:
|
||||
|
||||
Reference in New Issue
Block a user