Inestable fix
This commit is contained in:
parent
8eeac2e998
commit
a2d3b2784f
|
@ -7,6 +7,7 @@ import stock
|
|||
import ir
|
||||
import bom
|
||||
import configuration
|
||||
import product
|
||||
|
||||
|
||||
def register():
|
||||
|
@ -19,6 +20,7 @@ def register():
|
|||
ir.Cron,
|
||||
bom.BOM,
|
||||
bom.BOMDirectCost,
|
||||
product.ProductAverageCost,
|
||||
module='production_accounting', type_='model')
|
||||
Pool.register(
|
||||
production.ProductionDetailed,
|
||||
|
|
9
bom.py
9
bom.py
|
@ -67,6 +67,15 @@ class BOMDirectCost(ModelSQL, ModelView):
|
|||
uom = fields.Many2One('product.uom', 'UoM')
|
||||
quantity = fields.Float('Quantity', required=True, digits=(16,2))
|
||||
notes = fields.Char('Notes')
|
||||
kind = fields.Selection([
|
||||
('labour', 'Labour'),
|
||||
('imc', 'IMC'),
|
||||
('', ''),
|
||||
], 'Kind')
|
||||
|
||||
@staticmethod
|
||||
def default_kind():
|
||||
return 'labour'
|
||||
|
||||
@fields.depends('product', 'uom')
|
||||
def on_change_with_uom(self, name=None):
|
||||
|
|
10
product.py
10
product.py
|
@ -1,6 +1,6 @@
|
|||
# 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.model import fields
|
||||
from trytond.model import fields, ModelSQL, ModelView
|
||||
from trytond.pyson import Eval
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
|
||||
|
@ -9,6 +9,14 @@ from trytond.modules.account_product.product import account_used
|
|||
account_names = ['account_stock', 'account_production']
|
||||
|
||||
|
||||
class ProductAverageCost(ModelSQL, ModelView):
|
||||
'Product Average Cost'
|
||||
__name__ = 'product.average_cost'
|
||||
product = fields.Many2One('product.product', 'Product', readonly=True)
|
||||
date = fields.Date('Date', readonly=True)
|
||||
cost_price = fields.Numeric('Cost Price', digits=(16, 2), readonly=True)
|
||||
|
||||
|
||||
class Category(metaclass=PoolMeta):
|
||||
__name__ = 'product.category'
|
||||
account_production = fields.MultiValue(fields.Many2One('account.account',
|
||||
|
|
164
production.py
164
production.py
|
@ -10,6 +10,9 @@ from trytond.modules.company import CompanyReport
|
|||
from trytond.i18n import gettext
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.report import Report
|
||||
from trytond.modules.product import price_digits, round_price
|
||||
|
||||
ZERO = Decimal(0)
|
||||
|
||||
|
||||
def round_dec(number):
|
||||
|
@ -23,25 +26,26 @@ class Production(metaclass=PoolMeta):
|
|||
out_account_move = fields.Many2One('account.move', 'Out Account Move',
|
||||
states={'readonly': True})
|
||||
warehouse_origin = fields.Many2One('stock.location', 'Warehouse Origin',
|
||||
domain=[
|
||||
('type', '=', 'warehouse'),
|
||||
])
|
||||
domain=[('type', '=', 'warehouse')])
|
||||
warehouse_target = fields.Many2One('stock.location', 'Warehouse Target',
|
||||
domain=[
|
||||
('type', '=', 'warehouse'),
|
||||
])
|
||||
domain=[('type', '=', 'warehouse')])
|
||||
warehouse_moves = fields.One2Many('stock.move', 'origin', 'Warehouse Moves')
|
||||
material_costs = fields.Numeric('Material Costs', digits=(16, 2),
|
||||
readonly=True)
|
||||
labour_costs = fields.Numeric('Labour Costs', digits=(16, 2), readonly=True)
|
||||
imc_costs = fields.Numeric('IMC Costs', digits=(16, 2), readonly=True)
|
||||
total_cost = fields.Numeric('Total Cost', digits=(16, 2), readonly=True)
|
||||
|
||||
@staticmethod
|
||||
def default_warehouse_origin():
|
||||
config = Pool.get('production.configuration')(1)
|
||||
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)
|
||||
config = Pool().get('production.configuration')(1)
|
||||
if config.warehouse_origin:
|
||||
return config.warehouse_target.id
|
||||
return
|
||||
|
@ -53,23 +57,23 @@ class Production(metaclass=PoolMeta):
|
|||
rec.create_account_move('wait', 'in_account_move')
|
||||
rec.create_stock_move('in')
|
||||
|
||||
@classmethod
|
||||
def draft(cls, productions):
|
||||
super(Production, cls).draft(productions)
|
||||
cursor = Transaction().connection.cursor()
|
||||
moves = []
|
||||
for p in productions:
|
||||
if p.raw_production_move:
|
||||
cursor.execute("DELETE FROM account_move WHERE id = %s" % (p.raw_production_move.id))
|
||||
if p.production_finished_move:
|
||||
cursor.execute("DELETE FROM account_move WHERE id = %s" % (p.production_finished_move.id))
|
||||
for m in p.inputs:
|
||||
moves.append(str(m.id))
|
||||
for m in p.outputs:
|
||||
moves.append(str(m.id))
|
||||
if moves:
|
||||
moves_ids = ", ".join(moves)
|
||||
cursor.execute("UPDATE stock_move SET state='draft' WHERE id in (%s)" % (moves_ids))
|
||||
# @classmethod
|
||||
# def draft(cls, productions):
|
||||
# super(Production, cls).draft(productions)
|
||||
# cursor = Transaction().connection.cursor()
|
||||
# moves = []
|
||||
# for p in productions:
|
||||
# if p.raw_production_move:
|
||||
# cursor.execute("DELETE FROM account_move WHERE id = %s" % (p.raw_production_move.id))
|
||||
# if p.production_finished_move:
|
||||
# cursor.execute("DELETE FROM account_move WHERE id = %s" % (p.production_finished_move.id))
|
||||
# for m in p.inputs:
|
||||
# moves.append(str(m.id))
|
||||
# for m in p.outputs:
|
||||
# moves.append(str(m.id))
|
||||
# if moves:
|
||||
# moves_ids = ", ".join(moves)
|
||||
# cursor.execute("UPDATE stock_move SET state='draft' WHERE id in (%s)" % (moves_ids))
|
||||
|
||||
@classmethod
|
||||
def assign(cls, records):
|
||||
|
@ -80,9 +84,12 @@ class Production(metaclass=PoolMeta):
|
|||
@classmethod
|
||||
def done(cls, records):
|
||||
super(Production, cls).done(records)
|
||||
# for record in records:
|
||||
# record.create_account_move('done')
|
||||
# record.create_stock_move('done')
|
||||
for rec in records:
|
||||
rec.create_account_move('done', 'out_account_move')
|
||||
rec.update_product_cost()
|
||||
|
||||
def update_product_cost(self):
|
||||
pass
|
||||
|
||||
def check_cost(self):
|
||||
# Fix me super method for pass check_cost validation
|
||||
|
@ -110,6 +117,7 @@ class Production(metaclass=PoolMeta):
|
|||
lines = []
|
||||
balance = []
|
||||
costs_lines = {}
|
||||
to_update = {}
|
||||
if kind == 'wait':
|
||||
date_ = self.planned_date
|
||||
for _in in self.inputs:
|
||||
|
@ -142,53 +150,59 @@ class Production(metaclass=PoolMeta):
|
|||
|
||||
for account_id, debit in costs_lines.items():
|
||||
_line = {
|
||||
'description': '',
|
||||
'description': self.number,
|
||||
'account': account_id,
|
||||
'debit': sum(debit),
|
||||
'credit': 0,
|
||||
}
|
||||
lines.append(_line)
|
||||
to_update['material_costs'] = sum(debit)
|
||||
|
||||
# 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")
|
||||
# })
|
||||
if kind == 'done':
|
||||
date_ = self.effective_date
|
||||
cost_finished_stock = []
|
||||
output = self.outputs[0]
|
||||
account_expense = output.product.account_expense_used
|
||||
lines.append({
|
||||
'description': self.number,
|
||||
'account': account_expense.id,
|
||||
'debit': 0,
|
||||
'credit': self.cost,
|
||||
})
|
||||
cost_finished_stock.append(self.cost)
|
||||
total_labour = []
|
||||
total_imc = []
|
||||
for dc in self.bom.direct_costs:
|
||||
account_id = dc.product.account_expense_used.id
|
||||
amount = Decimal(dc.quantity) * dc.product.cost_price
|
||||
amount = Decimal(round(amount, 2))
|
||||
lines.append({
|
||||
'description': self.number,
|
||||
'account': account_id,
|
||||
'debit': 0,
|
||||
'credit': amount,
|
||||
})
|
||||
cost_finished_stock.append(amount)
|
||||
if dc.kind == 'labour':
|
||||
total_labour.append(amount)
|
||||
elif dc.kind == 'imc':
|
||||
total_imc.append(amount)
|
||||
|
||||
period_id = Period.find(self.company.id, date=self.planned_date)
|
||||
account_stock = output.product.account_stock_used
|
||||
lines.append({
|
||||
'description': self.number,
|
||||
'account': account_stock.id,
|
||||
'debit': sum(cost_finished_stock),
|
||||
'credit': 0,
|
||||
})
|
||||
total_labour = sum(total_labour)
|
||||
total_imc = sum(total_imc)
|
||||
to_update['material_costs'] = self.cost
|
||||
to_update['labour_costs'] = total_labour
|
||||
to_update['imc_costs'] = total_imc
|
||||
to_update['total_cost'] = total_imc + total_labour + self.cost
|
||||
|
||||
period_id = Period.find(self.company.id, date=date_)
|
||||
move, = Move.create([{
|
||||
'journal': journal.id,
|
||||
'period': period_id,
|
||||
|
@ -198,28 +212,30 @@ class Production(metaclass=PoolMeta):
|
|||
'origin': str(self),
|
||||
'description': self.number,
|
||||
}])
|
||||
Move.post([move])
|
||||
|
||||
self.write([self], {field: move})
|
||||
Move.post([move])
|
||||
to_update[field] = move.id
|
||||
self.write([self], to_update)
|
||||
|
||||
def create_stock_move(self, kind, field=None):
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
to_create = []
|
||||
if kind == 'in':
|
||||
for input in inputs:
|
||||
for input in self.inputs:
|
||||
to_create.append({
|
||||
'product': input.product,
|
||||
'quantity': input.quantity,
|
||||
'from_location': warehouse_origin.storage_location.id,
|
||||
'to_location': self.location.storage_location.id,
|
||||
'from_location': self.warehouse_origin.storage_location.id,
|
||||
'to_location': self.warehouse.storage_location.id,
|
||||
'origin': str(self),
|
||||
'effective_date': self.effective_date,
|
||||
'unit_price': input.unit_price,
|
||||
'uom': input.uom.id,
|
||||
'state': 'draft',
|
||||
})
|
||||
moves = Move.create(to_create)
|
||||
# self.write([self], {'warehouse_moves': move})
|
||||
Move.do(moves)
|
||||
|
||||
|
||||
class ProductionReport(CompanyReport):
|
||||
|
|
|
@ -7,6 +7,7 @@ depends:
|
|||
account
|
||||
production
|
||||
account_stock_latin
|
||||
analytic_account
|
||||
xml:
|
||||
message.xml
|
||||
configuration.xml
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
<field name="uom"/>
|
||||
<label name="quantity"/>
|
||||
<field name="quantity"/>
|
||||
<label name="kind"/>
|
||||
<field name="kind"/>
|
||||
<label name="notes"/>
|
||||
<field name="notes"/>
|
||||
</form>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0"?>
|
||||
<tree>
|
||||
<tree editable="1">
|
||||
<field name="kind"/>
|
||||
<field name="product"/>
|
||||
<field name="uom"/>
|
||||
<field name="quantity"/>
|
||||
|
|
|
@ -11,6 +11,7 @@ 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">
|
||||
<newline />
|
||||
<label name="in_account_move"/>
|
||||
<field name="in_account_move"/>
|
||||
<label name="out_account_move"/>
|
||||
|
@ -19,6 +20,14 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="warehouse_origin"/>
|
||||
<label name="warehouse_target"/>
|
||||
<field name="warehouse_target"/>
|
||||
<label name="material_costs"/>
|
||||
<field name="material_costs"/>
|
||||
<label name="labour_costs"/>
|
||||
<field name="labour_costs"/>
|
||||
<label name="imc_costs"/>
|
||||
<field name="imc_costs"/>
|
||||
<label name="total_cost"/>
|
||||
<field name="total_cost"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/field[@name='planned_start_date']" position="after">
|
||||
<label name="effective_date"/>
|
||||
|
|
Loading…
Reference in New Issue