add report balance to sales
This commit is contained in:
parent
02e75ea907
commit
fe958b90f4
@ -1,7 +1,7 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
from . import (agended, calibration, configuration, contract, diary,
|
||||
from . import (agended, balance_sale_party, calibration, configuration, contract, diary,
|
||||
equipment, party, product, maintenance, move, purchase, sale)
|
||||
|
||||
__all__ = ['register']
|
||||
@ -37,6 +37,7 @@ def register():
|
||||
purchase.Line,
|
||||
sale.Sale,
|
||||
sale.SaleLine,
|
||||
balance_sale_party.BalanceSalePartyStart,
|
||||
maintenance.MaintenanceService,
|
||||
maintenance.MaintenanceServiceLine,
|
||||
maintenance.MaintenanceLine,
|
||||
@ -46,6 +47,7 @@ def register():
|
||||
move.ShipmentOut,
|
||||
move.ShipmentInternal,
|
||||
move.ShipmentOutReturn,
|
||||
balance_sale_party.BalanceSalePartyStart,
|
||||
module='optical_equipment', type_='model')
|
||||
Pool.register(
|
||||
agended.AssingAgended,
|
||||
@ -53,6 +55,7 @@ def register():
|
||||
contract.CreateContract,
|
||||
equipment.NewPropietary,
|
||||
maintenance.NewPropietaryMaintenance,
|
||||
balance_sale_party.PrintBalanceSaleParty,
|
||||
module='optical_equipment', type_='wizard')
|
||||
Pool.register(
|
||||
calibration.CalibrationReport,
|
||||
@ -61,4 +64,5 @@ def register():
|
||||
maintenance.MaintenanceServiceReport,
|
||||
move.PickingListDeliveryReport,
|
||||
move.CapacitationReport,
|
||||
balance_sale_party.BalanceSaleParty,
|
||||
module='optical_equipment', type_='report')
|
||||
|
133
balance_sale_party.py
Normal file
133
balance_sale_party.py
Normal file
@ -0,0 +1,133 @@
|
||||
# The COPYRIGHT file at the top level of this repository contains the full
|
||||
# copyright notices and license terms.
|
||||
from trytond.model import ModelView, fields
|
||||
from trytond.wizard import Wizard, StateView, Button, StateReport
|
||||
from trytond.report import Report
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.pyson import Eval
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
__all__ = ['BalancePartyStart', 'PrintBalanceParty', 'BalanceParty']
|
||||
|
||||
class BalanceSalePartyStart(ModelView):
|
||||
'Balance Party Start'
|
||||
__name__ = 'optical_equipment.print_balance_sale_party.start'
|
||||
|
||||
party = fields.Many2One('party.party', 'Party', required=True)
|
||||
start_period = fields.Many2One('account.period', 'Start Period',
|
||||
domain=[
|
||||
('start_date', '<=', (Eval('end_period'), 'start_date')),
|
||||
], depends=['fiscalyear', 'end_period'])
|
||||
end_period = fields.Many2One('account.period', 'End Period',
|
||||
domain=[
|
||||
('start_date', '>=', (Eval('start_period'), 'start_date'))
|
||||
],
|
||||
depends=['start_period'])
|
||||
company = fields.Many2One('company.company', 'Company', required=True)
|
||||
party_type = fields.Selection([('out', 'Customer')], "Party Type", required=True)
|
||||
|
||||
@staticmethod
|
||||
def default_company():
|
||||
return Transaction().context.get('company')
|
||||
|
||||
@staticmethod
|
||||
def default_party_type():
|
||||
return 'out'
|
||||
|
||||
|
||||
class PrintBalanceSaleParty(Wizard):
|
||||
'Print Balance Sale Party'
|
||||
__name__ = 'optical_equipment.print_balance_sale_party'
|
||||
|
||||
start = StateView('optical_equipment.print_balance_sale_party.start',
|
||||
'optical_equipment.print_balance_sale_party_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-print', default=True),
|
||||
])
|
||||
|
||||
print_ = StateReport('optical_equipment.balance_sale_party')
|
||||
|
||||
def do_print_(self, action):
|
||||
party = None
|
||||
party_type = None
|
||||
|
||||
if self.start.party:
|
||||
party = self.start.party.id
|
||||
if self.start.party_type:
|
||||
party_type = self.start.party_type
|
||||
|
||||
data = {
|
||||
'company': self.start.company.id,
|
||||
'party': party,
|
||||
'party_type': party_type
|
||||
}
|
||||
return action, data
|
||||
|
||||
def transition_print_(self):
|
||||
return 'end'
|
||||
|
||||
|
||||
class BalanceSaleParty(Report):
|
||||
__name__ = 'optical_equipment.balance_sale_party'
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, header, data):
|
||||
report_context = super(BalanceSaleParty, cls).get_context(records, header, data)
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
Period = pool.get('account.period')
|
||||
Sale = pool.get('sale.sale')
|
||||
Party = pool.get('party.party')
|
||||
start_period = None
|
||||
end_period = None
|
||||
party = None
|
||||
company = Company(data['company'])
|
||||
dom_sale = [('state', 'in', ["processing", "done"])]
|
||||
|
||||
if data.get('party'):
|
||||
party = data['party']
|
||||
dom_sale.append(('party', '=', party))
|
||||
|
||||
if data.get('start_period'):
|
||||
start_period = Period(data['start_period'])
|
||||
dom_sale.append(('sale_date', '>=', start_period.start_date))
|
||||
if data.get('end_period'):
|
||||
end_period = Period(data['end_period'])
|
||||
dom_sale.append(('sale_date', '<=', end_period.start_date))
|
||||
|
||||
sales = Sale.search(dom_sale,
|
||||
order=[('sale_date', 'DESC'),
|
||||
('id', 'DESC')],)
|
||||
|
||||
res = {}
|
||||
dict_location = {}
|
||||
|
||||
id_ = party
|
||||
party_ = Party.search(['id', '=', party])[0]
|
||||
name = party_.rec_name
|
||||
|
||||
try:
|
||||
if party_.identifiers:
|
||||
id_number = party_.identifiers[0].code
|
||||
else:
|
||||
id_number = ''
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
res[id_] = {'name': name,
|
||||
'id_number': id_number,
|
||||
'party': party_
|
||||
}
|
||||
|
||||
if sales:
|
||||
res[id_]['sales'] = sales
|
||||
else:
|
||||
raise UserError(str("Este Tercero no Cuenta Con Ventas."))
|
||||
|
||||
report_context['records'] = res.values()
|
||||
report_context['start_period'] = start_period.name if start_period else '*'
|
||||
report_context['end_period'] = end_period.name if end_period else '*'
|
||||
report_context['company'] = company
|
||||
|
||||
return report_context
|
28
balance_sale_party.xml
Normal file
28
balance_sale_party.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.action.report" id="report_balance_sale_party">
|
||||
<field name="name">Balance by Party</field>
|
||||
<field name="model"></field>
|
||||
<field name="report_name">optical_equipment.balance_sale_party</field>
|
||||
<field name="report">optical_equipment/report/balance_sale_party.fods</field>
|
||||
<field name="template_extension">ods</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="print_balance_sale_party_start_view_form">
|
||||
<field name="model">optical_equipment.print_balance_sale_party.start</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">print_balance_sale_party_start_form</field>
|
||||
</record>
|
||||
<record model="ir.action.wizard" id="wizard_print_balance_sale_party">
|
||||
<field name="name">Print Balance Sale by Party</field>
|
||||
<field name="wiz_name">optical_equipment.print_balance_sale_party</field>
|
||||
</record>
|
||||
<menuitem
|
||||
parent="sale.menu_reporting"
|
||||
action="wizard_print_balance_sale_party"
|
||||
id="menu_print_balance_sale_party"
|
||||
icon="tryton-print"/>
|
||||
</data>
|
||||
</tryton>
|
1
report/.~lock.balance_sale_party.fods#
Normal file
1
report/.~lock.balance_sale_party.fods#
Normal file
@ -0,0 +1 @@
|
||||
,root,rodia,16.04.2023 20:17,file:///root/.config/libreoffice/4;
|
1178
report/balance_sale_party.fods
Normal file
1178
report/balance_sale_party.fods
Normal file
File diff suppressed because it is too large
Load Diff
@ -25,4 +25,5 @@ xml:
|
||||
product.xml
|
||||
purchase.xml
|
||||
sale.xml
|
||||
balance_sale_party.xml
|
||||
shipment.xml
|
15
view/print_balance_sale_party_start_form.xml
Normal file
15
view/print_balance_sale_party_start_form.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="party"/>
|
||||
<field name="party"/>
|
||||
<label name="company"/>
|
||||
<field name="company"/>
|
||||
<label name="start_period"/>
|
||||
<field name="start_period"/>
|
||||
<label name="end_period"/>
|
||||
<field name="end_period"/>
|
||||
<label name="party_type"/>
|
||||
<field name="party_type"/>
|
||||
</form>
|
Loading…
Reference in New Issue
Block a user