Fix views

This commit is contained in:
Oscar 2022-02-11 12:05:45 -05:00
parent 132dcdc73c
commit e30470993c
6 changed files with 219 additions and 1 deletions

View file

@ -12,6 +12,7 @@ from . import price_list
from . import product
from . import source
from . import goal
from . import statement
def register():
@ -22,6 +23,8 @@ def register():
shop.SaleShopEmployee,
user.User,
sale.Sale,
statement.Journal,
statement.StatementLine,
stock.ShipmentOut,
stock.ShipmentOutReturn,
sale.SaleBySupplierStart,

169
statement.py Normal file
View file

@ -0,0 +1,169 @@
# This file is part of the sale_pos module for Tryton.
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from datetime import date
from decimal import Decimal
from trytond.model import fields, ModelView, ModelSQL, Workflow
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from trytond.wizard import Button, StateTransition, StateView, Wizard
from trytond.pyson import Eval
from trytond.i18n import gettext
from trytond.exceptions import UserError
_ZERO = Decimal("0.0")
PAYMENT_CODES = [
('', ''),
('1', 'Instrumento no definido'),
('10', 'Efectivo'),
('44', 'Nota Cambiaria'),
('20', 'Cheque'),
('48', 'Tarjeta Crédito'),
('49', 'Tarjeta Débito'),
('42', 'Consignación bancaria'),
('47', 'Transferencia Débito Bancaria'),
('45', 'Transferencia Crédito Bancaria'),
]
class Journal(metaclass=PoolMeta):
__name__ = 'account.statement.journal'
payment_means_code = fields.Selection(
PAYMENT_CODES, 'Payment Means Code', required=True)
kind = fields.Selection([
('cash', 'Cash'),
('electronic', 'Electronic'),
('transfer', 'Transfer'),
('payment', 'Payment'),
('other', 'Other'),
], 'Kind', select=True)
default_start_balance = fields.Numeric('Default Start Balance by Device')
require_voucher = fields.Boolean('Require Voucher')
require_party = fields.Boolean('Require Party')
party = fields.Many2One('party.party', 'Party',
states={'invisible': ~Eval('require_party')})
@staticmethod
def default_kind():
return 'cash'
@staticmethod
def default_require_party():
return False
class StatementLine(metaclass=PoolMeta):
__name__ = 'account.statement.line'
sale = fields.Many2One('sale.sale', 'Sale', ondelete='RESTRICT')
voucher = fields.Char('Voucher Number')
def get_move_line2(self, values):
'Return counterpart Move Line for the amount'
move_id = values['move_id']
journal_account = values.get('journal_account', False)
account = values.get('account')
amount = values.get('amount')
credit = _ZERO
debit = _ZERO
if journal_account:
if amount >= 0:
debit = amount
else:
credit = abs(amount)
else:
if amount >= 0:
credit = amount
else:
debit = abs(amount)
if not account:
raise UserError(
gettext('sale_pos.msg_account_statement_journal',
s=self.journal.rec_name))
res = {
'description': self.description,
'debit': debit,
'credit': credit,
'account': account.id,
'party': self.party.id if account.party_required else None,
'move': move_id,
}
return res
def _get_move2(self):
# Return Move for the grouping key
pool = Pool()
Move = pool.get('account.move')
MoveLine = pool.get('account.move.line')
Period = pool.get('account.period')
Journal = pool.get('account.statement.journal')
company_id = self.statement.company.id
period_id = Period.find(company_id, date=self.date)
_move = {
'period': period_id,
'journal': self.statement.journal.journal.id,
'date': self.date,
'origin': str(self.statement),
'company': company_id,
'state': 'draft',
}
move, = Move.create([_move])
move_line1 = self.get_move_line2({
'move_id': move.id,
'account': self.account,
'amount': self.amount
})
extra_amount = 0
if hasattr(self, 'extra_amount') and self.extra_amount:
extra_amount = self.extra_amount
move_line2 = self.get_move_line2({
'account': self.statement.journal.account,
'move_id': move.id,
'amount': self.amount + extra_amount,
'journal_account': True,
})
if self.statement.journal.require_party and self.statement.journal.party:
party = self.statement.journal.party.id
move_line2['party'] = party
to_create = [move_line1, move_line2]
journals = Journal.search([
('kind', '=', 'cash')
])
journal_ids = [j.id for j in journals]
# Just add extra amount to move line when payment is different to cash
if hasattr(self, 'extra_amount') and self.extra_amount > 0 and \
self.statement.journal.id not in journal_ids:
if journals:
journal = journals[0]
move_line3 = self.get_move_line2({
'account': journal.account,
'move_id': move.id,
'amount': self.extra_amount
})
to_create.append(move_line3)
MoveLine.create(to_create)
return move
@classmethod
def post_move(cls, lines):
super(StatementLine, cls).post_move(lines)
for s in lines:
if s.invoice and s.move and s.invoice.state != 'paid':
invoice = s.invoice
move = s.move
payment_lines = [l for l in move.lines if l.account
== invoice.account and l.party == invoice.party]
invoice.add_payment_lines({invoice: payment_lines})
def create_move(self):
# Overwrite sale_pos > create_move
move = self._get_move2()
self.write([self], {'move': move.id})

26
statement.xml Normal file
View file

@ -0,0 +1,26 @@
<?xml version="1.0"?>
<!-- This file is part of the sale_pos module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="statement_journal_view_form">
<field name="model">account.statement.journal</field>
<field name="inherit" ref="account_statement.statement_journal_view_form"/>
<field name="name">statement_journal_form</field>
</record>
<record model="ir.ui.view" id="statement_line_view_form">
<field name="model">account.statement.line</field>
<field name="inherit" ref="account_statement.statement_line_view_form"/>
<field name="name">statement_line_form</field>
</record>
<record model="ir.ui.view" id="statement_line_view_tree">
<field name="model">account.statement.line</field>
<field name="inherit" ref="account_statement.statement_line_view_tree"/>
<field name="name">statement_line_tree</field>
</record>
</data>
</tryton>

View file

@ -1,5 +1,5 @@
[tryton]
version=6.0.5
version=6.0.6
depends:
company
account_invoice

View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of the sale_payment module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/form/field[@name='move']" position="after">
<label name="create_uid"/>
<field name="create_uid"/>
</xpath>
</data>

View file

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<!-- This file is part of the sale_payment module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/tree/field[@name='description']" position="after">
<field name="voucher"/>
<field name="sale"/>
</xpath>
</data>