minor fix report
This commit is contained in:
parent
6aacff6aa4
commit
d97f7330e8
Binary file not shown.
88
purchase.py
88
purchase.py
|
@ -167,50 +167,70 @@ class PurchaseAnalyticReport(Report):
|
|||
@classmethod
|
||||
def compute_amount_tax(cls, line):
|
||||
Tax = Pool().get('account.tax')
|
||||
tax_list = Tax.compute(line.taxes,
|
||||
line.unit_price or Decimal('0.0'),
|
||||
line.quantity or 0.0)
|
||||
tax_list = Tax.compute(Tax.browse(line['taxes']),
|
||||
line['unit_price'] or Decimal('0.0'),
|
||||
line['quantity'] or 0.0)
|
||||
return sum([t['amount'] for t in tax_list], Decimal('0.0'))
|
||||
|
||||
@classmethod
|
||||
def _get_rec(cls, line):
|
||||
if line['analytic_accounts.']:
|
||||
analytic_account = line['analytic_accounts.'][0]['account.']
|
||||
inv_unit_price = Decimal(0)
|
||||
if line['invoice_lines.']:
|
||||
inv_unit_price = line['invoice_lines.'][0]['unit_price']
|
||||
|
||||
value = {
|
||||
'reference': line['purchase.']['reference'],
|
||||
'purchase_date': line['purchase.']['purchase_date'],
|
||||
'state': line['purchase.']['state'],
|
||||
'shipment_state': line['purchase.']['shipment_state'],
|
||||
'invoice_state': line['purchase.']['invoice_state'],
|
||||
'id_number': line['purchase.']['party.']['id_number'],
|
||||
'name': line['purchase.']['party.']['name'],
|
||||
'description': line['description'],
|
||||
'unit_name': line['unit.']['name'],
|
||||
'quantity': line['quantity'],
|
||||
'unit_price': line['unit_price'],
|
||||
'analytic_account': analytic_account['code'] + ' ' + analytic_account['name'] if analytic_account else '',
|
||||
'taxes': list(line['taxes']),
|
||||
'qty_received': sum([r['quantity'] for r in line['moves.']]),
|
||||
'amount': line['amount'],
|
||||
'inv_unit_price': inv_unit_price
|
||||
}
|
||||
tax_amount = cls.compute_amount_tax(value)
|
||||
full_amount = value['amount'] + tax_amount
|
||||
value.update({
|
||||
'tax_amount': tax_amount,
|
||||
'full_amount': full_amount,
|
||||
})
|
||||
return value
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, records, header, data):
|
||||
report_context = super().get_context(records, header, data)
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
Purchase = pool.get('purchase.purchase')
|
||||
purchases = Purchase.search([
|
||||
('company', '=', data['company']),
|
||||
('purchase_date', '>=', data['start_date']),
|
||||
('purchase_date', '<=', data['end_date']),
|
||||
], order=[('purchase_date', 'ASC')])
|
||||
PurchaseLine = pool.get('purchase.line')
|
||||
fields_names = ['purchase.reference', 'purchase.purchase_date', 'purchase.party.id_number',
|
||||
'purchase.party.name', 'description', 'unit.name', 'quantity', 'unit_price',
|
||||
'purchase.state', 'purchase.shipment_state', 'purchase.invoice_state',
|
||||
'analytic_accounts.account.name', 'analytic_accounts.account.code', 'taxes',
|
||||
'invoice_lines.unit_price', 'moves.quantity', 'amount'
|
||||
]
|
||||
|
||||
lines = PurchaseLine.search_read([
|
||||
('purchase.company', '=', data['company']),
|
||||
('purchase.purchase_date', '>=', data['start_date']),
|
||||
('purchase.purchase_date', '<=', data['end_date']),
|
||||
], fields_names=fields_names, order=[('purchase.purchase_date', 'ASC')])
|
||||
|
||||
records = []
|
||||
for purchase in purchases:
|
||||
for line in purchase.lines:
|
||||
analytic = None
|
||||
qty_received = 0
|
||||
unit_price_inv_sup = None
|
||||
if hasattr(line, 'analytic_accounts') and line.analytic_accounts:
|
||||
for acc in line.analytic_accounts:
|
||||
if acc.account:
|
||||
code = acc.account.code or ''
|
||||
name = acc.account.name
|
||||
analytic = code + '-' + name
|
||||
tax_amount = cls.compute_amount_tax(line)
|
||||
setattr(line, 'analytic', analytic)
|
||||
setattr(line, 'tax_amount', tax_amount)
|
||||
setattr(line, 'full_amount', tax_amount + line.amount)
|
||||
for shipment in purchase.shipments:
|
||||
for move in shipment.incoming_moves:
|
||||
if move.product.id == line.product.id:
|
||||
qty_received += move.quantity
|
||||
for inv_line in line.invoice_lines:
|
||||
if inv_line.type == 'line':
|
||||
unit_price_inv_sup = inv_line.unit_price
|
||||
setattr(line, 'qty_received', qty_received)
|
||||
setattr(line, 'unit_price_inv_sup', unit_price_inv_sup)
|
||||
|
||||
records.append(purchase)
|
||||
records_append = records.append
|
||||
get_rec = cls._get_rec
|
||||
for line in lines:
|
||||
records_append(get_rec(line))
|
||||
|
||||
report_context['records'] = records
|
||||
report_context['company'] = Company(data['company'])
|
||||
|
|
|
@ -4,9 +4,6 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<tryton>
|
||||
<data>
|
||||
|
||||
<menuitem parent="purchase.menu_purchase" id="menu_purchase_reporting"
|
||||
name="Reporting"/>
|
||||
|
||||
<record model="ir.action.report" id="report_purchase_analytic">
|
||||
<field name="name">Purchase Analytic Report</field>
|
||||
<field name="model"></field>
|
||||
|
@ -22,9 +19,9 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="name">Wizard Purchase Analytic Report</field>
|
||||
<field name="wiz_name">purchase_report.analytic</field>
|
||||
</record>
|
||||
<menuitem name="Purchase Analytic" parent="purchase_report.menu_purchase_reporting"
|
||||
sequence="2" id="menu_purchase_analytic_report"
|
||||
action="wizard_print_purchase_report_analytic"/>
|
||||
|
||||
<menuitem name="Purchase Analytic" parent="account_col.menu_purchase_reporting" sequence="20"
|
||||
action="wizard_print_purchase_report_analytic" id="menu_purchase_analytic_report"/>
|
||||
|
||||
<record model="ir.ui.view" id="purchase_line_view_form">
|
||||
<field name="model">purchase.line</field>
|
||||
|
|
Loading…
Reference in New Issue