mirror of
https://bitbucket.org/presik/trytonpsk-sale_pos.git
synced 2023-12-14 07:13:02 +01:00
121 lines
4.1 KiB
Python
121 lines
4.1 KiB
Python
# 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 decimal import Decimal
|
|
from trytond.model import ModelView, fields
|
|
from trytond.wizard import Wizard, StateView, Button, StateReport
|
|
from trytond.report import Report
|
|
from trytond.transaction import Transaction
|
|
from trytond.pool import Pool
|
|
|
|
|
|
class SaleAccountMovesStart(ModelView):
|
|
'Sale Account Moves Start'
|
|
__name__ = 'sale_pos.sale_account_moves.start'
|
|
company = fields.Many2One('company.company', 'Company', required=True)
|
|
start_date = fields.Date('Start Date', required=True)
|
|
end_date = fields.Date('End Date', required=True)
|
|
shop = fields.Many2One('sale.shop', 'Shop', required=True)
|
|
|
|
@staticmethod
|
|
def default_company():
|
|
return Transaction().context.get('company')
|
|
|
|
|
|
class SaleAccountMoves(Wizard):
|
|
'Sale Account Moves'
|
|
__name__ = 'sale_pos.sale_account_moves'
|
|
start = StateView('sale_pos.sale_account_moves.start',
|
|
'sale_pos.sale_account_moves_start_view_form', [
|
|
Button('Cancel', 'end', 'tryton-cancel'),
|
|
Button('Print', 'print_', 'tryton-print', default=True),
|
|
])
|
|
print_ = StateReport('sale_pos.sale_account_moves_report')
|
|
|
|
def do_print_(self, action):
|
|
data = {
|
|
'company': self.start.company.id,
|
|
'start_date': self.start.start_date,
|
|
'end_date': self.start.end_date,
|
|
'shop': self.start.shop.id
|
|
}
|
|
return action, data
|
|
|
|
def transition_print_(self):
|
|
return 'end'
|
|
|
|
|
|
class SaleAccountMovesReport(Report):
|
|
__name__ = 'sale_pos.sale_account_moves_report'
|
|
|
|
@classmethod
|
|
def get_line(cls, line, date_, number, origin):
|
|
return {
|
|
'date': date_,
|
|
'move': number,
|
|
'party': line.party.name if line.party else '',
|
|
'reference': line.reference,
|
|
'description': line.description,
|
|
'origin': origin,
|
|
'debit': line.debit,
|
|
'credit': line.credit,
|
|
}
|
|
|
|
@classmethod
|
|
def get_context(cls, records, header, data):
|
|
report_context = super().get_context(records, header, data)
|
|
pool = Pool()
|
|
Invoice = pool.get('account.invoice')
|
|
Statement = pool.get('account.statement')
|
|
Company = pool.get('company.company')
|
|
Shop = pool.get('sale.shop')
|
|
company = Company(data['company'])
|
|
shop = Shop(data['shop'])
|
|
|
|
statements = Statement.search([
|
|
('sale_device.shop', '=', shop.id),
|
|
('date', '>=', data['start_date']),
|
|
('date', '<=', data['end_date']),
|
|
])
|
|
|
|
_records = []
|
|
rec_extend = _records.extend
|
|
for st in statements:
|
|
for line in st.lines:
|
|
if line.move:
|
|
rec_extend(line.move.lines)
|
|
|
|
invoices = Invoice.search([
|
|
('shop', '=', data['shop']),
|
|
('invoice_date', '>=', data['start_date']),
|
|
('invoice_date', '<=', data['end_date']),
|
|
('move', '!=', None),
|
|
('type', '=', 'out'),
|
|
])
|
|
for inv in invoices:
|
|
rec_extend(inv.move.lines)
|
|
|
|
records = {}
|
|
for line in _records:
|
|
account_id = line.account.id
|
|
mv = line.move
|
|
date_ = mv.date
|
|
number = mv.number
|
|
origin = mv.origin.rec_name if mv.origin else ''
|
|
new_line = cls.get_line(line, date_, number, origin)
|
|
try:
|
|
records[account_id]['lines'].append(new_line)
|
|
records[account_id]['total_debit'].append(line.debit)
|
|
records[account_id]['total_credit'].append(line.credit)
|
|
except:
|
|
records[account_id] = {
|
|
'code': line.account.code,
|
|
'name': line.account.name,
|
|
'lines': [new_line],
|
|
'total_debit': [line.debit],
|
|
'total_credit': [line.credit],
|
|
}
|
|
|
|
report_context['shop'] = shop.name
|
|
report_context['company'] = company
|
|
report_context['records'] = records.values()
|
|
return report_context
|