Inestable release

This commit is contained in:
Oscar 2022-02-07 16:14:55 -05:00
parent 69b49ba7d7
commit 8eeac2e998
7 changed files with 177 additions and 69 deletions

View File

@ -6,10 +6,12 @@ import account
import stock
import ir
import bom
import configuration
def register():
Pool.register(
configuration.Configuration,
production.Production,
account.Move,
stock.Move,

10
configuration.py Normal file
View File

@ -0,0 +1,10 @@
# 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.pool import PoolMeta
from trytond.model import fields
class Configuration(metaclass=PoolMeta):
__name__ = 'production.configuration'
warehouse_origin = fields.Many2One('stock.location', 'Warehouse Origin')
warehouse_target = fields.Many2One('stock.location', 'Warehouse Target')

14
configuration.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!-- This file is part of 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="production_configuration_view_form">
<field name="model">production.configuration</field>
<field name="inherit" ref="production.production_configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
</data>
</tryton>

View File

@ -18,14 +18,40 @@ def round_dec(number):
class Production(metaclass=PoolMeta):
__name__ = 'production'
raw_production_move = fields.Many2One('account.move', 'Raw - Production Move',
in_account_move = fields.Many2One('account.move', 'In Account Move',
states={'readonly': True})
production_finished_move = fields.Many2One('account.move', 'Production - Finished Move',
out_account_move = fields.Many2One('account.move', 'Out Account Move',
states={'readonly': True})
warehouse_origin = fields.Many2One('stock.location', 'Warehouse Origin',
domain=[
('type', '=', 'warehouse'),
])
warehouse_target = fields.Many2One('stock.location', 'Warehouse Target',
domain=[
('type', '=', 'warehouse'),
])
warehouse_moves = fields.One2Many('stock.move', 'origin', 'Warehouse Moves')
@staticmethod
def default_warehouse_origin():
config = Pool.get('production.configuration')(1)
if config.warehouse_origin:
return config.warehouse_origin.id
return
@staticmethod
def default_warehouse_target():
config = Pool.get('production.configuration')(1)
if config.warehouse_origin:
return config.warehouse_target.id
return
@classmethod
def __setup__(cls):
super(Production, cls).__setup__()
def wait(cls, records):
super(Production, cls).wait(records)
for rec in records:
rec.create_account_move('wait', 'in_account_move')
rec.create_stock_move('in')
@classmethod
def draft(cls, productions):
@ -48,20 +74,21 @@ class Production(metaclass=PoolMeta):
@classmethod
def assign(cls, records):
super(Production, cls).assign(records)
# for record in records:
# record.create_account_move_stock('assigned')
# for rec in records:
# rec.create_account_move('out')
@classmethod
def done(cls, records):
super(Production, cls).done(records)
# for record in records:
# record.create_account_move_stock('done')
# record.create_account_move('done')
# record.create_stock_move('done')
def check_cost(self):
# Fix me super method for pass check_cost validation
pass
def create_account_move_stock(self, kind):
def create_account_move(self, kind, field=None):
pool = Pool()
Move = pool.get('account.move')
Period = pool.get('account.period')
@ -81,86 +108,118 @@ class Production(metaclass=PoolMeta):
)
lines = []
balance = Decimal(0)
if kind == 'assigned':
balance = []
costs_lines = {}
if kind == 'wait':
date_ = self.planned_date
for _in in self.inputs:
if _in.product.cost_price == 0:
product = _in.product
if product.cost_price == 0:
continue
category = _in.product.template.account_category
category = product.template.account_category
if not category or not category.account_stock:
raise UserError(gettext(
'production_accounting.msg_category_account_stock',
product=_in.product.rec_name
product=product.rec_name
))
account_id = category.account_stock.id
credit = round_dec(_in.product.cost_price * Decimal(_in.quantity))
account_stock_id = category.account_stock.id
credit = round_dec(product.cost_price * Decimal(_in.quantity))
credit = round(credit, 0)
_line = {
'description': _in.product.template.name,
'account': account_id,
'description': product.template.name,
'account': account_stock_id,
'debit': 0,
'credit': credit
}
if category.account_stock.party_required:
_line['party'] = self.company.party.id
lines.append(_line)
balance.append(credit)
account_expense_id = category.account_expense.id
try:
costs_lines[account_expense_id].append(credit)
except Exception as e:
costs_lines[account_expense_id] = [credit]
for account_id, debit in costs_lines.items():
_line = {
'description': '',
'account': account_id,
'debit': sum(debit),
'credit': 0,
}
lines.append(_line)
balance += credit
amount = 0
for _out in self.outputs:
credit = debit = Decimal("0.00")
category = _out.product.template.account_category
# if not category or not category.account_stock_production:
# raise UserError(gettext(
# 'production_accounting.msg_category_account_stock',
# product=_out.product.rec_name
# ))
# account_production_id = category.account_stock_production.id
account_production_id = category.account_stock.id
if kind == 'assigned':
debit = balance
if kind == 'done':
credit = round_dec(_out.product.cost_price * Decimal(_out.quantity))
credit = round(credit, 0)
amount += credit
_line = {
'description': _out.product.template.name,
'account': account_production_id,
'debit': debit,
'credit': credit
}
if category.account_stock.party_required:
_line['party'] = self.company.party.id
lines.append(_line)
if kind == 'done':
account_stock_id = self.product.template.account_category.account_stock.id
lines.append({
'description': self.product.template.name,
'account': account_stock_id,
'debit': amount,
'credit': Decimal("0.00")
})
# if kind == 'done':
# debit = balance
# amount = 0
# for _out in self.outputs:
# credit = debit = Decimal("0.00")
# category = _out.product.template.account_category
# # if not category or not category.account_stock_production:
# # raise UserError(gettext(
# # 'production_accounting.msg_category_account_stock',
# # product=_out.product.rec_name
# # ))
# # account_production_id = category.account_stock_production.id
# account_production_id = category.account_stock.id
# if kind == 'assigned':
# debit = balance
# if kind == 'done':
# credit = round_dec(_out.product.cost_price * Decimal(_out.quantity))
# credit = round(credit, 0)
# amount += credit
#
# _line = {
# 'description': _out.product.template.name,
# 'account': account_production_id,
# 'debit': debit,
# 'credit': credit
# }
# if category.account_stock.party_required:
# _line['party'] = self.company.party.id
# lines.append(_line)
#
# if kind == 'done':
# account_stock_id = self.product.template.account_category.account_stock.id
# lines.append({
# 'description': self.product.template.name,
# 'account': account_stock_id,
# 'debit': amount,
# '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,
'date': date_,
'state': 'draft',
'lines': [('create', lines)],
'origin': str(self),
# 'description': self.description,
'description': self.number,
}])
Move.post([move])
if kind == 'assigned':
field = 'raw_production_move'
self.write([self], {field: move})
# elif kind == 'done':
# field = 'production_finished_move'
self.write([self], {field: move})
def create_stock_move(self, kind, field=None):
pool = Pool()
Move = pool.get('stock.move')
to_create = []
if kind == 'in':
for input in inputs:
to_create.append({
'product': input.product,
'quantity': input.quantity,
'from_location': warehouse_origin.storage_location.id,
'to_location': self.location.storage_location.id,
'origin': str(self),
'effective_date': self.effective_date,
'unit_price': input.unit_price,
'uom': input.uom.id,
})
moves = Move.create(to_create)
# self.write([self], {'warehouse_moves': move})
class ProductionReport(CompanyReport):

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.3
version=6.0.4
depends:
party
company
@ -9,6 +9,7 @@ depends:
account_stock_latin
xml:
message.xml
configuration.xml
production.xml
product.xml
bom.xml

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!-- This file is part of 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='production_sequence']" position="after">
<label name="warehouse_origin"/>
<field name="warehouse_origin"/>
<label name="warehouse_target"/>
<field name="warehouse_target"/>
</xpath>
</data>

View File

@ -11,10 +11,14 @@ this repository contains the full copyright notices and license terms. -->
<xpath expr="/form/notebook/page[@id='other']/label[@name='effective_start_date']" position="replace">
</xpath>
<xpath expr="/form/notebook/page[@id='other']/field[@name='cost']" position="after">
<label name="raw_production_move"/>
<field name="raw_production_move"/>
<label name="production_finished_move"/>
<field name="production_finished_move"/>
<label name="in_account_move"/>
<field name="in_account_move"/>
<label name="out_account_move"/>
<field name="out_account_move"/>
<label name="warehouse_origin"/>
<field name="warehouse_origin"/>
<label name="warehouse_target"/>
<field name="warehouse_target"/>
</xpath>
<xpath expr="/form/field[@name='planned_start_date']" position="after">
<label name="effective_date"/>
@ -22,4 +26,9 @@ this repository contains the full copyright notices and license terms. -->
<label name="effective_start_date"/>
<field name="effective_start_date"/>
</xpath>
<xpath expr="/form/notebook/page[@id='other']" position="after">
<page string="Stock Moves" id="warehouse_stock_moves">
<field name="warehouse_moves" colspan="4"/>
</page>
</xpath>
</data>