add colum imp consumo in report warehouse

This commit is contained in:
Wilson Gomez 2023-01-12 10:59:47 -05:00
parent 0aa38ab700
commit 174b72b1d4
6 changed files with 54 additions and 26 deletions

View File

@ -1,7 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of # This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms. # this repository contains the full copyright notices and license terms.
from trytond.model import fields, ModelSQL, ModelView, Workflow from trytond.model import fields, ModelView, Workflow
from trytond.pool import Pool, PoolMeta from trytond.pool import PoolMeta
from trytond.modules.company.model import employee_field from trytond.modules.company.model import employee_field
from trytond.pyson import Eval, If from trytond.pyson import Eval, If
@ -12,8 +12,12 @@ class CreateInventoriesStart(metaclass=PoolMeta):
assign_to = employee_field('Assing To') assign_to = employee_field('Assing To')
category = fields.Many2One('product.category', 'Category', 'Product Categories') category = fields.Many2One('product.category', 'Category', 'Product Categories')
products = fields.Many2Many('product.product', None, None, 'Products', products = fields.Many2Many('product.product', None, None, 'Products',
domain=[If(Eval('category'), domain=[
('template.categories', '=', Eval('category')), ())], If(
Eval('category'),
('template.categories', '=', Eval('category')),
())
],
depends=['categories']) depends=['categories'])
@ -21,7 +25,8 @@ class CreateInventories(metaclass=PoolMeta):
__name__ = 'stock.inventory.create' __name__ = 'stock.inventory.create'
def get_inventory(self, location, Inventory): def get_inventory(self, location, Inventory):
inventory = super(CreateInventories, self).get_inventory(location, Inventory) inventory = super(CreateInventories, self).get_inventory(
location, Inventory)
if self.start.products: if self.start.products:
self.start.complete_lines = False self.start.complete_lines = False
products = [s.id for s in self.start.products] products = [s.id for s in self.start.products]
@ -40,10 +45,12 @@ class InventoryLine(metaclass=PoolMeta):
def __setup__(cls): def __setup__(cls):
super(InventoryLine, cls).__setup__() super(InventoryLine, cls).__setup__()
cls._states = { cls._states = {
'readonly': ~Eval('inventory_state').in_(["draft", "checkup", "pre_count"]) 'readonly': ~Eval('inventory_state').in_([
"draft", "checkup", "pre_count"])
} }
cls.quantity.states = cls._states cls.quantity.states = cls._states
class Inventory(metaclass=PoolMeta): class Inventory(metaclass=PoolMeta):
'Stock Inventory' 'Stock Inventory'
__name__ = 'stock.inventory' __name__ = 'stock.inventory'
@ -58,9 +65,13 @@ class Inventory(metaclass=PoolMeta):
@classmethod @classmethod
def __setup__(cls): def __setup__(cls):
super(Inventory, cls).__setup__() super(Inventory, cls).__setup__()
cls.state.selection.extend([('pre_count', 'Pre-count'), ('checkup', 'Checkup')]) cls.state.selection.extend([
('pre_count', 'Pre-count'),
('checkup', 'Checkup')])
cls._states = { cls._states = {
'readonly': (~Eval('state').in_(["draft", "checkup", "pre_count"]) | ~Eval('location') 'readonly': (
~Eval('state').in_(["draft", "checkup", "pre_count"])
| ~Eval('location')
| ~Eval('date')), | ~Eval('date')),
} }
cls.lines.states = cls._states cls.lines.states = cls._states

View File

@ -31,14 +31,16 @@ class ProductTemplatePosition(ModelSQL, ModelView):
__name__ = 'product_template.position' __name__ = 'product_template.position'
# _rec_name = 'position' # _rec_name = 'position'
position = fields.Many2One('product.position', 'Position', required=True, ondelete='CASCADE') position = fields.Many2One('product.position', 'Position', required=True,
template = fields.Many2One('product.template', 'Template', required=True, ondelete='RESTRICT') ondelete='CASCADE')
warehouse =fields.Function(fields.Many2One('stock.location', 'Warehouse'), 'on_change_with_warehouse') template = fields.Many2One('product.template', 'Template', required=True,
ondelete='RESTRICT')
warehouse = fields.Function(fields.Many2One('stock.location', 'Warehouse'),
'on_change_with_warehouse')
@fields.depends('position') @fields.depends('position')
def on_change_with_warehouse(self, name=None): def on_change_with_warehouse(self, name=None):
warehouse = None warehouse = None
if self.position: if self.position:
warehouse = self.position.warehouse.id warehouse = self.position.warehouse.id
return warehouse return warehouse

View File

@ -49,7 +49,6 @@ class Product(metaclass=PoolMeta):
('product', '=', self.id), ('product', '=', self.id),
('effective_date', '<=', target_date), ('effective_date', '<=', target_date),
], order=[('effective_date', 'DESC')], limit=1) ], order=[('effective_date', 'DESC')], limit=1)
print(' product >>>> ', avg_product)
if avg_product: if avg_product:
return avg_product[0].cost_price return avg_product[0].cost_price
else: else:

View File

@ -7,7 +7,9 @@ from sql import Table
from trytond.modules.company import CompanyReport from trytond.modules.company import CompanyReport
from trytond.pool import Pool, PoolMeta from trytond.pool import Pool, PoolMeta
from trytond.wizard import Wizard, StateTransition, StateView, Button, StateReport from trytond.wizard import (
Wizard, StateTransition, StateView,
Button, StateReport)
from trytond.transaction import Transaction from trytond.transaction import Transaction
from trytond.model import ModelView, fields from trytond.model import ModelView, fields
from trytond.report import Report from trytond.report import Report
@ -413,11 +415,13 @@ class ShipmentDetailedStart(ModelView):
('internal', 'Internal'), ('internal', 'Internal'),
], 'Type Shipment', required=True) ], 'Type Shipment', required=True)
grouped = fields.Boolean('Grouped') grouped = fields.Boolean('Grouped')
from_locations = fields.Many2Many('stock.location', None, None, 'From Location', domain=[ from_locations = fields.Many2Many('stock.location', None, None, 'From Location',
domain=[
('name', 'ilike', 'ZA%'), ('name', 'ilike', 'ZA%'),
('active', '=', True) ('active', '=', True)
]) ])
to_locations = fields.Many2Many('stock.location', None, None, 'To Location', domain=[ to_locations = fields.Many2Many('stock.location', None, None, 'To Location',
domain=[
('name', 'ilike', 'ZA%'), ('name', 'ilike', 'ZA%'),
('active', '=', True) ('active', '=', True)
]) ])
@ -439,12 +443,12 @@ class ShipmentDetailed(Wizard):
print_ = StateReport('stock.shipment.shipment_detailed.report') print_ = StateReport('stock.shipment.shipment_detailed.report')
def do_print_(self, action): def do_print_(self, action):
from_locations=None from_locations = None
to_locations=None to_locations = None
if self.start.from_locations: if self.start.from_locations:
from_locations= [l.id for l in self.start.from_locations] from_locations = [n.id for n in self.start.from_locations]
if self.start.to_locations: if self.start.to_locations:
to_locations= [l.id for l in self.start.to_locations] to_locations = [n.id for n in self.start.to_locations]
data = { data = {
'company': self.start.company.id, 'company': self.start.company.id,
@ -494,11 +498,14 @@ class ShipmentDetailedReport(Report):
) )
shipments_id = [model + ',' + str(sh['id']) for sh in shipments] shipments_id = [model + ',' + str(sh['id']) for sh in shipments]
fields_names = [ fields_names = [
'product.account_category.name', 'product.name', 'product.code', 'product.cost_price', 'product.account_category.name', 'product.name', 'product.code',
'quantity', 'to_location.name', 'from_location.name', 'shipment.reference', 'product.cost_price', 'quantity', 'to_location.name',
'from_location.name', 'shipment.reference',
'effective_date', 'shipment.number' 'effective_date', 'shipment.number'
] ]
fields = ModelShipment.fields_get(fields_names=['operation_center', 'customer', 'supplier', 'incoming_moves', 'analytic_account']) fields = ModelShipment.fields_get(fields_names=[
'operation_center', 'customer', 'supplier',
'incoming_moves', 'analytic_account'])
if 'operation_center' in fields.keys(): if 'operation_center' in fields.keys():
fields_names.append('shipment.operation_center.rec_name') fields_names.append('shipment.operation_center.rec_name')

View File

@ -417,6 +417,7 @@ class WarehouseReport(Report):
dom_products.append([('template.product_suppliers.party', 'in', data['suppliers'])]) dom_products.append([('template.product_suppliers.party', 'in', data['suppliers'])])
total_amount = 0 total_amount = 0
total_amount_imp = 0
values = {} values = {}
products = [] products = []
if data['group_by_location']: if data['group_by_location']:
@ -434,17 +435,21 @@ class WarehouseReport(Report):
try: try:
suppliers[sup_id]['products'].append(p) suppliers[sup_id]['products'].append(p)
suppliers[sup_id]['total_amount'].append(p.amount_cost if p.amount_cost else 0) suppliers[sup_id]['total_amount'].append(p.amount_cost if p.amount_cost else 0)
suppliers[sup_id]['total_amount_imp'].append(p.extra_tax * Deciaml(p.quantity) if p.extra_tax else 0)
except: except:
suppliers[sup_id] = {} suppliers[sup_id] = {}
suppliers[sup_id]['products'] = [p] suppliers[sup_id]['products'] = [p]
suppliers[sup_id]['party'] = prod_sup.party suppliers[sup_id]['party'] = prod_sup.party
suppliers[sup_id]['total_amount'] = [p.amount_cost if p.amount_cost else 0] suppliers[sup_id]['total_amount'] = [p.amount_cost if p.amount_cost else 0]
suppliers[sup_id]['total_amount_imp'] = [p.extra_tax * Decimal(p.quantity) if p.extra_tax else 0]
total_amount = sum([p.amount_cost for p in prdts if p.amount_cost]) total_amount = sum([p.amount_cost for p in prdts if p.amount_cost])
total_amount_imp = sum([p.extra_tax * Decimal(p.quantity) for p in prdts if p.extra_tax])
values[l.id] = { values[l.id] = {
'name': l.name, 'name': l.name,
'products': prdts, 'products': prdts,
'suppliers': suppliers.values(), 'suppliers': suppliers.values(),
'total_amount': total_amount 'total_amount': total_amount,
'total_amount_imp': total_amount_imp
} }
products = values.values() products = values.values()
else: else:
@ -454,6 +459,7 @@ class WarehouseReport(Report):
if data['only_minimal_level']: if data['only_minimal_level']:
products = [p for p in products if p.quantity <= min_quantities[p.id]] products = [p for p in products if p.quantity <= min_quantities[p.id]]
total_amount = sum([p.amount_cost for p in products if p.amount_cost]) total_amount = sum([p.amount_cost for p in products if p.amount_cost])
total_amount_imp = sum([p.extra_tax * Decimal(p.quantity) for p in products if p.extra_tax])
suppliers = {} suppliers = {}
if data['group_by_supplier']: if data['group_by_supplier']:
for p in products: for p in products:
@ -464,11 +470,13 @@ class WarehouseReport(Report):
try: try:
suppliers[sup_id]['products'].append(p) suppliers[sup_id]['products'].append(p)
suppliers[sup_id]['total_amount'].append(p.amount_cost if p.amount_cost else 0) suppliers[sup_id]['total_amount'].append(p.amount_cost if p.amount_cost else 0)
suppliers[sup_id]['total_amount_imp'].append(p.extra_tax * Decimal(p.quantity) if p.extra_tax else 0)
except: except:
suppliers[sup_id] = {} suppliers[sup_id] = {}
suppliers[sup_id]['products'] = [p] suppliers[sup_id]['products'] = [p]
suppliers[sup_id]['party'] = prod_sup.party suppliers[sup_id]['party'] = prod_sup.party
suppliers[sup_id]['total_amount'] = [p.amount_cost if p.amount_cost else 0] suppliers[sup_id]['total_amount'] = [p.amount_cost if p.amount_cost else 0]
suppliers[sup_id]['total_amount_imp'] = [p.extra_tax * Decimal(p.quantity) if p.extra_tax else 0]
products = suppliers.values() products = suppliers.values()
cursor = Transaction().connection.cursor() cursor = Transaction().connection.cursor()
@ -488,6 +496,7 @@ class WarehouseReport(Report):
report_context['group_by_supplier'] = data['group_by_supplier'] report_context['group_by_supplier'] = data['group_by_supplier']
report_context['records'] = products report_context['records'] = products
report_context['total_amount'] = total_amount report_context['total_amount'] = total_amount
report_context['total_amount_imp'] = total_amount_imp
report_context['last_purchase'] = last_purchase report_context['last_purchase'] = last_purchase
report_context['location'] = data['location_names'] report_context['location'] = data['location_names']
report_context['stock_date_end'] = data['to_date'] report_context['stock_date_end'] = data['to_date']

Binary file not shown.