mirror of
https://bitbucket.org/presik/trytonpsk-sale_pos_frontend_rest.git
synced 2023-12-14 06:12:59 +01:00
80 lines
2.4 KiB
Python
80 lines
2.4 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 trytond.transaction import Transaction
|
|
# from trytond.pyson import Eval
|
|
# from trytond.model import fields
|
|
from decimal import Decimal
|
|
from trytond.pool import PoolMeta, Pool
|
|
|
|
__all__ = ['Production']
|
|
|
|
def round_dec(number):
|
|
return Decimal(number.quantize(Decimal('.01')))
|
|
|
|
|
|
class Production(metaclass=PoolMeta):
|
|
__name__ = 'production'
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super(Production, cls).__setup__()
|
|
|
|
def create_account_move_stock(self, kind):
|
|
if kind == 'assigned':
|
|
return
|
|
pool = Pool()
|
|
Move = pool.get('account.move')
|
|
Line = pool.get('account.move.line')
|
|
Period = pool.get('account.period')
|
|
Journal = pool.get('account.journal')
|
|
Period = pool.get('account.period')
|
|
|
|
journals = Journal.search([
|
|
('code', '=', 'STO')
|
|
])
|
|
|
|
if journals:
|
|
journal = journals[0]
|
|
|
|
if not self.planned_date:
|
|
self.raise_user_error('planned_date_required')
|
|
|
|
lines = []
|
|
balance = Decimal(0)
|
|
for _in in self.inputs:
|
|
if _in.product.cost_price == 0:
|
|
continue
|
|
account_id = _in.product.template.account_category.account_stock.id
|
|
credit = round_dec(_in.product.cost_price * Decimal(_in.quantity))
|
|
# credit = round(credit, 0)
|
|
|
|
lines.append({
|
|
'description': _in.product.template.name,
|
|
'account': account_id,
|
|
'debit': Decimal("0.00"),
|
|
'credit': credit
|
|
})
|
|
|
|
balance += credit
|
|
|
|
account_stock_id = self.product.template.account_category.account_stock.id
|
|
lines.append({
|
|
'description': self.product.template.name,
|
|
'account': account_stock_id,
|
|
'debit': balance,
|
|
'credit': Decimal("0.00")
|
|
})
|
|
|
|
period_id = Period.find(self.company.id, date=self.planned_date)
|
|
move, = Move.create([{
|
|
'journal': journal.id,
|
|
'period': period_id,
|
|
'date': self.planned_date,
|
|
'state': 'draft',
|
|
'lines': [('create', lines)],
|
|
'origin': str(self),
|
|
}])
|
|
Move.post([move])
|
|
|
|
field = 'production_finished_move'
|
|
self.write([self], {field: move})
|