trytonpsk-sale_pos_frontend.../production.py

142 lines
4.7 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.pyson import Eval
from trytond.model import fields, ModelSQL, ModelView
from trytond.transaction import Transaction
from decimal import Decimal
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval
def round_dec(number):
return Decimal(number.quantize(Decimal('.01')))
STATES= {'required': True}
class WorkStation(ModelSQL, ModelView):
"Work Station"
__name__ = 'production.workstation'
name = fields.Char('Name', states=STATES)
code = fields.Char('Code', states=STATES)
printers = fields.Many2Many('production.workstation.pos_printer', 'work_station', 'printer', 'Printers')
class WorkStationPrinter(ModelSQL, ModelView):
"Work Station"
__name__ = 'production.workstation.pos_printer'
work_station = fields.Many2One('production.workstation', 'Work Station')
printer = fields.Many2One('sale.pos_printer', 'Printer')
class ConfigurationTask(ModelSQL, ModelView):
"Configuration Task"
__name__ = 'production.configuration_task'
name = fields.Char('Name', states=STATES)
description = fields.Text('Description')
ldm = fields.Many2One('production.bom', 'LDM', states=STATES)
product = fields.Many2One('product.product', 'Product',
search_context={
'outputs': Eval('_parent_ldm', {}).get('outputs'),
})
work_station = fields.Many2One('production.workstation', 'Work Station', states=STATES)
@fields.depends('ldm', 'product', '_parent_ldm.outputs')
def on_change_ldm(self):
print(self.ldm, 'valid')
if self.ldm:
self.product = self.ldm.outputs[0].product
class Task(ModelSQL, ModelView):
"Task"
__name__ = 'production.task'
name = fields.Char('Name', states=STATES)
description = fields.Text('Description')
ldm = fields.Many2One('production.bom', 'LDM', states=STATES)
work_station = fields.Many2One('production.workstation', 'Work Station', states=STATES)
planned_date = fields.Date('Planned Date')
quantity = fields.Integer('Quantity')
state = fields.Selection([('pending', 'Pending'), ('done', 'Done')], 'State')
@classmethod
def __setup__(cls):
super(Task, cls).__setup__()
# 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')
# company_id = Transaction().context.get('company')
# company = pool.get('company.company')(company_id)
# company_party = company.party
# 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)
# FIXME
# 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,
# 'party': company_party.id,
# '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,
# 'party': company_party.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})