Add production account move
This commit is contained in:
parent
a6372e7e87
commit
8015839e29
6686
production.fodt
6686
production.fodt
File diff suppressed because it is too large
Load Diff
101
production.py
101
production.py
|
@ -107,6 +107,12 @@ class Production(metaclass=PoolMeta):
|
|||
'Analytic Account Services', domain=_analytic_dom)
|
||||
subproductions = fields.One2Many('production.sub', 'production',
|
||||
'Sub-Productions')
|
||||
account_production = fields.Many2One('account.account',
|
||||
'Account Production', domain=[
|
||||
('closed', '!=', True),
|
||||
('type.stock', '=', True),
|
||||
('company', '=', Eval('context', {}).get('company', -1)),
|
||||
])
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
|
@ -114,6 +120,9 @@ class Production(metaclass=PoolMeta):
|
|||
cls._buttons.update({
|
||||
'generate_sub': {
|
||||
'invisible': Eval('state').in_(['done']),
|
||||
},
|
||||
'post_production': {
|
||||
'invisible': Eval('state').in_(['done']),
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -152,6 +161,12 @@ class Production(metaclass=PoolMeta):
|
|||
if to_create:
|
||||
Sub.create([to_create])
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
def post_production(cls, records):
|
||||
for rec in records:
|
||||
cls.create_account_move(rec, 'partial')
|
||||
|
||||
@staticmethod
|
||||
def default_warehouse_origin():
|
||||
config = Pool().get('production.configuration')(1)
|
||||
|
@ -180,7 +195,6 @@ class Production(metaclass=PoolMeta):
|
|||
super(Production, cls).run(records)
|
||||
for rec in records:
|
||||
rec.create_stock_move_sub()
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def done(cls, records):
|
||||
|
@ -235,7 +249,6 @@ class Production(metaclass=PoolMeta):
|
|||
@classmethod
|
||||
def get_production_lines(cls, rec, date_, factor):
|
||||
""" Get Production Account Move Lines """
|
||||
|
||||
cost_production = []
|
||||
output = rec.bom.outputs[0]
|
||||
lines = []
|
||||
|
@ -250,12 +263,14 @@ class Production(metaclass=PoolMeta):
|
|||
'credit': amount,
|
||||
'party': company,
|
||||
}
|
||||
cost_production.append(amount)
|
||||
cost_production.append(amount or 0)
|
||||
cls.set_analytic_lines(line, date_, rec.analytic_account_materials)
|
||||
lines.append(line)
|
||||
|
||||
account_id = None
|
||||
for cost in rec.costs:
|
||||
if cost.account_move:
|
||||
continue
|
||||
account_id = cost.product.account_expense_used.id
|
||||
line_ = {
|
||||
'description': cost.product.rec_name,
|
||||
|
@ -266,7 +281,7 @@ class Production(metaclass=PoolMeta):
|
|||
}
|
||||
cls.set_analytic_lines(line_, date_, cost.analytic_account)
|
||||
lines.append(line_)
|
||||
cost_production.append(cost.amount)
|
||||
cost_production.append(cost.amount or 0)
|
||||
output_account_category = output.product.account_category.account_stock_in
|
||||
stock_in = {
|
||||
'description': output.product.rec_name,
|
||||
|
@ -278,6 +293,44 @@ class Production(metaclass=PoolMeta):
|
|||
lines.append(stock_in)
|
||||
return lines
|
||||
|
||||
@classmethod
|
||||
def get_production_lines_partial(cls, rec, date_, factor, kind=None):
|
||||
""" Get Production Account Move Lines Partial """
|
||||
cost_production = []
|
||||
output = rec.bom.outputs[0]
|
||||
lines = []
|
||||
company = Transaction().context.get('company')
|
||||
|
||||
account_id = None
|
||||
for cost in rec.costs:
|
||||
if cost.account_move:
|
||||
continue
|
||||
account_id = cost.product.account_expense_used.id
|
||||
if not cost.amount:
|
||||
continue
|
||||
line_ = {
|
||||
'description': cost.product.rec_name,
|
||||
'account': account_id,
|
||||
'debit': 0,
|
||||
'credit': cost.amount or 0,
|
||||
# 'party': company,
|
||||
}
|
||||
cls.set_analytic_lines(line_, date_, cost.analytic_account)
|
||||
lines.append(line_)
|
||||
cost_production.append(cost.amount or 0)
|
||||
|
||||
account_partial_stock = rec.account_production.id
|
||||
stock_in = {
|
||||
'description': output.product.rec_name,
|
||||
'account': account_partial_stock,
|
||||
'debit': sum(cost_production),
|
||||
'credit': 0,
|
||||
# 'party': company,
|
||||
}
|
||||
lines.append(stock_in)
|
||||
print('lines....', lines)
|
||||
return lines
|
||||
|
||||
@classmethod
|
||||
def get_consumption_lines(cls, inputs, factor, date_, args=None):
|
||||
""" Get Consumption Account Move Lines """
|
||||
|
@ -356,6 +409,9 @@ class Production(metaclass=PoolMeta):
|
|||
if kind == 'done':
|
||||
date_ = rec.effective_date
|
||||
lines = cls.get_production_lines(rec, date_, factor)
|
||||
if kind == 'partial':
|
||||
date_ = date.today()
|
||||
lines = cls.get_production_lines_partial(rec, date_, factor, kind)
|
||||
|
||||
period_id = Period.find(rec.company.id, date=date_)
|
||||
|
||||
|
@ -371,6 +427,11 @@ class Production(metaclass=PoolMeta):
|
|||
|
||||
Move.post([move])
|
||||
cls.write([rec], {'out_account_move': move.id})
|
||||
for cost in rec.costs:
|
||||
if cost.account_move:
|
||||
continue
|
||||
cost.account_move = move.id
|
||||
cost.save()
|
||||
|
||||
def create_stock_move(self, kind, field=None):
|
||||
pool = Pool()
|
||||
|
@ -473,11 +534,11 @@ class Production(metaclass=PoolMeta):
|
|||
labour_costs = []
|
||||
for cost in self.costs:
|
||||
if cost.kind == 'indirect':
|
||||
indirect_costs.append(cost.amount)
|
||||
indirect_costs.append(cost.amount or 0)
|
||||
elif cost.kind == 'labour':
|
||||
labour_costs.append(cost.amount)
|
||||
labour_costs.append(cost.amount or 0)
|
||||
elif cost.kind == 'service':
|
||||
services_costs.append(cost.amount)
|
||||
services_costs.append(cost.amount or 0)
|
||||
|
||||
self.indirect_costs = sum(indirect_costs)
|
||||
self.services_costs = sum(services_costs)
|
||||
|
@ -508,6 +569,8 @@ class ProductionCost(ModelSQL, ModelView):
|
|||
('service', 'Service'),
|
||||
], 'Kind', required=True)
|
||||
notes = fields.Text('Notes')
|
||||
account_move = fields.Many2One('account.move', 'Account Move',
|
||||
states={'readonly': True})
|
||||
|
||||
@fields.depends('product', 'unit', 'unit_price')
|
||||
def on_change_product(self, name=None):
|
||||
|
@ -521,30 +584,6 @@ class ProductionCost(ModelSQL, ModelView):
|
|||
return round(self.unit_price * Decimal(self.quantity), 2)
|
||||
|
||||
|
||||
class RoutingStep(metaclass=PoolMeta):
|
||||
__name__ = 'production.routing.step'
|
||||
work_center = fields.Many2One('production.work.center', 'Work Center')
|
||||
|
||||
def get_work(self, production, work_center_picker):
|
||||
"Return work instance for the production using the work center picker"
|
||||
pool = Pool()
|
||||
Work = pool.get('production.work')
|
||||
|
||||
work = Work()
|
||||
work.sequence = self.sequence
|
||||
work.operation = self.operation
|
||||
work.production = production
|
||||
work.company = production.company
|
||||
if self.operation.work_center_category:
|
||||
work.work_center = work_center_picker(
|
||||
production.work_center, self.operation.work_center_category)
|
||||
elif self.work_center:
|
||||
work.work_center = self.work_center
|
||||
else:
|
||||
work.work_center = production.work_center
|
||||
return work
|
||||
|
||||
|
||||
class ProductionReport(CompanyReport):
|
||||
'Production Report'
|
||||
__name__ = 'production.report'
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
<field name="quantity"/>
|
||||
<label name="amount"/>
|
||||
<field name="amount"/>
|
||||
<label name="account_move"/>
|
||||
<field name="account_move"/>
|
||||
<label name="analytic_account"/>
|
||||
<field name="analytic_account" widget="selection"/>
|
||||
<newline />
|
||||
|
|
|
@ -4,6 +4,8 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<data>
|
||||
<xpath expr="/form/notebook/page[@id='other']/field[@name='cost']" position="after">
|
||||
<newline />
|
||||
<label name="account_production"/>
|
||||
<field name="account_production"/>
|
||||
<label name="warehouse_origin"/>
|
||||
<field name="warehouse_origin"/>
|
||||
<label name="warehouse_target"/>
|
||||
|
@ -49,6 +51,8 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<label name="total_cost"/>
|
||||
<field name="total_cost"/>
|
||||
</group>
|
||||
<button name="post_production" string="Post Production Partial"
|
||||
icon="tryton-ok" colspan="2"/>
|
||||
</page>
|
||||
</xpath>
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue