Inestable 04

This commit is contained in:
Oscar 2022-02-09 16:07:31 -05:00
parent e1b2ccb08e
commit b615fadc1c
4 changed files with 203 additions and 16 deletions

View File

@ -13,17 +13,19 @@ import product
def register():
Pool.register(
configuration.Configuration,
product.ProductAverageCost,
production.Production,
production.ProductionDetailedStart,
production.ProcessProductionAsyncStart,
account.Move,
stock.Move,
production.ProductionDetailedStart,
ir.Cron,
bom.BOM,
bom.BOMDirectCost,
product.ProductAverageCost,
module='production_accounting', type_='model')
Pool.register(
production.ProductionDetailed,
production.ProcessProductionAsync,
production.DoneProductions,
module='production_accounting', type_='wizard')
Pool.register(

View File

@ -102,7 +102,6 @@ class Production(metaclass=PoolMeta):
def create_account_move(self, kind, field=None):
pool = Pool()
Move = pool.get('account.move')
Period = pool.get('account.period')
Journal = pool.get('account.journal')
Period = pool.get('account.period')
@ -308,6 +307,166 @@ class DoneProductions(Wizard):
return 'end'
class ProcessProductionAsyncStart(ModelView):
'Process Production Async Start'
__name__ = 'production.process_production_async.start'
company = fields.Many2One('company.company', 'Company', required=True)
shop = fields.Many2One('sale.shop', 'Shop', required=True)
date = fields.Date('Start Date', required=True)
@staticmethod
def default_company():
return Transaction().context.get('company')
class ProcessProductionAsync(Wizard):
'Process Production Async'
__name__ = 'production.process_production_async'
start = StateView('production.process_production_async.start',
'production_accounting.process_production_async_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Ok', 'accept', 'tryton-ok', default=True),
])
accept = StateTransition()
def create_move(self, lines, journal, period_id):
Move = Pool().get('account.move')
for l in lines:
print('account id ', l['account'], l['debit'], l['credit'])
move, = Move.create([{
'journal': journal.id,
'period': period_id,
'date': self.start.date,
'state': 'draft',
'lines': [('create', lines)],
'description': '',
# 'origin': ,
}])
Move.post([move])
print('Asiento creado No ', move.number)
def create_production_moves(self, producibles, journal, period_id):
accounts = {}
lines = []
for product, values in producibles.items():
quantity = sum(values['quantity'])
bom = values['inputs'][0].bom
output = bom.outputs[0]
account_expense = output.product.account_expense_used
factor = Decimal(quantity / output.quantity)
for input in values['inputs']:
account_stock = input.product.account_stock_used
input_amount = input.product.cost_price * factor
try:
accounts[account_stock].append(input_amount)
except:
accounts[account_stock] = [input_amount]
tot_amount = []
for acc, amount in accounts.items():
amount = Decimal(round(sum(amount), 2))
line_ = {
'description': '',
'account': acc.id,
'debit': 0,
'credit': amount,
}
lines.append(line_)
tot_amount.append(amount)
line_ = {
'description': '',
'account': account_expense.id,
'debit': sum(tot_amount),
'credit': 0,
}
lines.append(line_)
self.create_move(lines, journal, period_id)
lines2 = []
dc_amount = []
for dc in bom.direct_costs:
account_id = dc.product.account_expense_used.id
amount = Decimal(dc.quantity) * dc.product.cost_price
amount = Decimal(round(amount, 2)) * factor
dc_amount.append(amount)
line_ = {
'description': '',
'account': account_id,
'debit': 0,
'credit': amount,
}
self.set_analytic_lines(line_, date_)
lines2.append(line_)
line_ = {
'description': '',
'account': account_expense.id,
'debit': 0,
'credit': sum(tot_amount),
}
stock_amount = sum(tot_amount) + sum(dc_amount)
lines2.append(line_)
line_ = {
'description': '',
'account': output.product.account_stock_used.id,
'debit': stock_amount,
'credit': 0,
}
lines2.append(line_)
self.create_move(lines2, journal, period_id)
def transition_accept(self):
pool = Pool()
SaleLine = pool.get('sale.line')
Shop = pool.get('sale.shop')
Period = pool.get('account.period')
Journal = pool.get('account.journal')
journals = Journal.search([
('code', '=', 'STO')
])
if journals:
journal = journals[0]
period_id = Period.find(self.start.company.id, date=self.start.date)
BOMOutput = pool.get('production.bom.output')
dom = [
('sale.state', 'in', ['processing', 'done']),
('sale.shop', '=', self.start.shop.id),
('sale.sale_date', '=', self.start.date),
('product.template.producible', '=', True),
('type', '=', 'line'),
]
lines = SaleLine.search(dom)
if not lines:
return 'end'
shop = Shop(self.start.shop.id)
producibles = {}
for line in lines:
product_id = line.product.id
try:
producibles[product_id]['quantity'].append(line.quantity)
except:
outputs = BOMOutput.search([
('product', '=', product_id)
])
if not outputs:
continue
output = outputs[0]
producibles[product_id] = {
'quantity': [line.quantity],
'inputs': output.bom.inputs,
}
self.create_production_moves(producibles, journal, period_id)
# self.create_stock_moves()
return 'end'
class ProductionDetailedStart(ModelView):
'Production Detailed Start'
__name__ = 'production.detailed.start'

View File

@ -44,18 +44,33 @@ this repository contains the full copyright notices and license terms. -->
<menuitem parent="menu_reports" sequence="100"
action="wizard_production_detailed" id="menu_production_detailed"/>
<record model="ir.action.report" id="report_production">
<field name="name">Production</field>
<field name="model">production</field>
<field name="report_name">production.report</field>
<field name="report">production_accounting/production.fodt</field>
<field name="template_extension">odt</field>
<field name="translatable">false</field>
</record>
<record model="ir.action.keyword" id="report_production_keyword">
<field name="keyword">form_print</field>
<field name="model">production,-1</field>
<field name="action" ref="report_production"/>
</record>
<record model="ir.action.report" id="report_production">
<field name="name">Production</field>
<field name="model">production</field>
<field name="report_name">production.report</field>
<field name="report">production_accounting/production.fodt</field>
<field name="template_extension">odt</field>
<field name="translatable">false</field>
</record>
<record model="ir.action.keyword" id="report_production_keyword">
<field name="keyword">form_print</field>
<field name="model">production,-1</field>
<field name="action" ref="report_production"/>
</record>
<record model="ir.ui.view" id="process_production_async_start_view_form">
<field name="model">production.process_production_async.start</field>
<field name="type">form</field>
<field name="name">process_production_async_start_form</field>
</record>
<record model="ir.action.wizard" id="wizard_process_production_async">
<field name="name">Process Production Async</field>
<field name="wiz_name">production.process_production_async</field>
</record>
<menuitem name="Create Production Async"
parent="production.menu_production"
sequence="2" id="menu_process_production_async"
action="wizard_process_production_async"/>
</data>
</tryton>

View File

@ -0,0 +1,11 @@
<?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. -->
<form>
<label name="company"/>
<field name="company" widget="selection"/>
<label name="date"/>
<field name="date"/>
<label name="shop"/>
<field name="shop" widget="selection"/>
</form>