mirror of
https://github.com/bringout/oca-ocb-project.git
synced 2026-04-21 16:02:10 +02:00
19.0 vanilla
This commit is contained in:
parent
a2f74aefd8
commit
4a4d12c333
844 changed files with 212348 additions and 270090 deletions
|
|
@ -1,3 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from . import project
|
||||
|
||||
from . import mrp_bom
|
||||
from . import mrp_production
|
||||
from . import project_project
|
||||
from . import stock
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class MrpBom(models.Model):
|
||||
_inherit = 'mrp.bom'
|
||||
|
||||
project_id = fields.Many2one('project.project', domain=[('is_template', '=', False)])
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MrpProduction(models.Model):
|
||||
_inherit = 'mrp.production'
|
||||
|
||||
project_id = fields.Many2one('project.project', compute='_compute_project_id', domain=[('is_template', '=', False)], readonly=False, store=True)
|
||||
|
||||
@api.depends('bom_id')
|
||||
def _compute_project_id(self):
|
||||
if not self.env.context.get('from_project_action'):
|
||||
for production in self:
|
||||
production.project_id = production.bom_id.project_id
|
||||
|
||||
def action_generate_bom(self):
|
||||
action = super().action_generate_bom()
|
||||
action['context']['default_project_id'] = self.project_id.id
|
||||
return action
|
||||
|
||||
def action_open_project(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'project.project',
|
||||
'view_mode': 'form',
|
||||
'res_id': self.project_id.id,
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, _lt
|
||||
from odoo.osv import expression
|
||||
|
||||
|
||||
class Project(models.Model):
|
||||
_inherit = "project.project"
|
||||
|
||||
production_count = fields.Integer(related="analytic_account_id.production_count", groups='mrp.group_mrp_user')
|
||||
workorder_count = fields.Integer(related="analytic_account_id.workorder_count", groups='mrp.group_mrp_user')
|
||||
bom_count = fields.Integer(related="analytic_account_id.bom_count", groups='mrp.group_mrp_user')
|
||||
|
||||
def action_view_mrp_production(self):
|
||||
self.ensure_one()
|
||||
action = self.env['ir.actions.actions']._for_xml_id('mrp.mrp_production_action')
|
||||
action['domain'] = [('analytic_account_id', '=', self.analytic_account_id.id)]
|
||||
action['context'] = {'default_analytic_account_id': self.analytic_account_id.id}
|
||||
if self.production_count == 1:
|
||||
action['view_mode'] = 'form'
|
||||
action['res_id'] = self.analytic_account_id.production_ids.id
|
||||
if 'views' in action:
|
||||
action['views'] = [
|
||||
(view_id, view_type)
|
||||
for view_id, view_type in action['views']
|
||||
if view_type == 'form'
|
||||
] or [False, 'form']
|
||||
return action
|
||||
|
||||
def action_view_mrp_bom(self):
|
||||
self.ensure_one()
|
||||
action = self.analytic_account_id.action_view_mrp_bom()
|
||||
if self.bom_count > 1:
|
||||
action['view_mode'] = 'tree,form,kanban'
|
||||
return action
|
||||
|
||||
def action_view_workorder(self):
|
||||
self.ensure_one()
|
||||
action = self.analytic_account_id.action_view_workorder()
|
||||
if self.workorder_count > 1:
|
||||
action['view_mode'] = 'tree,form,kanban,calendar,pivot,graph'
|
||||
return action
|
||||
|
||||
# ----------------------------
|
||||
# Project Updates
|
||||
# ----------------------------
|
||||
|
||||
def _get_profitability_labels(self):
|
||||
labels = super()._get_profitability_labels()
|
||||
labels['manufacturing_order'] = _lt('Manufacturing Orders')
|
||||
return labels
|
||||
|
||||
def _get_profitability_sequence_per_invoice_type(self):
|
||||
sequence_per_invoice_type = super()._get_profitability_sequence_per_invoice_type()
|
||||
sequence_per_invoice_type['manufacturing_order'] = 10
|
||||
return sequence_per_invoice_type
|
||||
|
||||
def _get_profitability_aal_domain(self):
|
||||
return expression.AND([
|
||||
super()._get_profitability_aal_domain(),
|
||||
[('category', '!=', 'manufacturing_order')],
|
||||
])
|
||||
|
||||
def _get_profitability_items(self, with_action=True):
|
||||
profitability_items = super()._get_profitability_items(with_action)
|
||||
mrp_category = 'manufacturing_order'
|
||||
mrp_aal_read_group = self.env['account.analytic.line'].sudo()._read_group(
|
||||
[('account_id', 'in', self.analytic_account_id.ids), ('category', '=', mrp_category)],
|
||||
['amount'],
|
||||
['account_id'],
|
||||
)
|
||||
if mrp_aal_read_group:
|
||||
can_see_manufactoring_order = with_action and len(self) == 1 and self.user_has_groups('mrp.group_mrp_user')
|
||||
mrp_costs = {
|
||||
'id': mrp_category,
|
||||
'sequence': self._get_profitability_sequence_per_invoice_type()[mrp_category],
|
||||
'billed': sum([res['amount'] for res in mrp_aal_read_group]),
|
||||
'to_bill': 0.0,
|
||||
}
|
||||
if can_see_manufactoring_order:
|
||||
mrp_costs['action'] = {'name': 'action_view_mrp_production', 'type': 'object'}
|
||||
costs = profitability_items['costs']
|
||||
costs['data'].append(mrp_costs)
|
||||
costs['total']['billed'] += mrp_costs['billed']
|
||||
return profitability_items
|
||||
|
||||
def _get_stat_buttons(self):
|
||||
buttons = super(Project, self)._get_stat_buttons()
|
||||
if self.user_has_groups('mrp.group_mrp_user'):
|
||||
buttons.extend([{
|
||||
'icon': 'flask',
|
||||
'text': _lt('Bills of Materials'),
|
||||
'number': self.bom_count,
|
||||
'action_type': 'object',
|
||||
'action': 'action_view_mrp_bom',
|
||||
'show': self.bom_count > 0,
|
||||
'sequence': 45,
|
||||
},
|
||||
{
|
||||
'icon': 'wrench',
|
||||
'text': _lt('Manufacturing Orders'),
|
||||
'number': self.production_count,
|
||||
'action_type': 'object',
|
||||
'action': 'action_view_mrp_production',
|
||||
'show': self.production_count > 0,
|
||||
'sequence': 46,
|
||||
}])
|
||||
return buttons
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models, _
|
||||
|
||||
|
||||
class ProjectProject(models.Model):
|
||||
_inherit = 'project.project'
|
||||
|
||||
bom_count = fields.Integer(compute='_compute_bom_count', groups='mrp.group_mrp_user', export_string_translation=False)
|
||||
production_count = fields.Integer(compute='_compute_production_count', groups='mrp.group_mrp_user', export_string_translation=False)
|
||||
|
||||
def _compute_bom_count(self):
|
||||
bom_count_per_project = dict(
|
||||
self.env['mrp.bom']._read_group(
|
||||
[('project_id', 'in', self.ids)],
|
||||
['project_id'], ['__count']
|
||||
)
|
||||
)
|
||||
for project in self:
|
||||
project.bom_count = bom_count_per_project.get(project)
|
||||
|
||||
def _compute_production_count(self):
|
||||
production_count_per_project = dict(
|
||||
self.env['mrp.production']._read_group(
|
||||
[('project_id', 'in', self.ids)],
|
||||
['project_id'], ['__count']
|
||||
)
|
||||
)
|
||||
for project in self:
|
||||
project.production_count = production_count_per_project.get(project)
|
||||
|
||||
def action_view_mrp_bom(self):
|
||||
self.ensure_one()
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'mrp.bom',
|
||||
'domain': [('project_id', '=', self.id)],
|
||||
'name': self.env._('Bills of Materials'),
|
||||
'view_mode': 'list,kanban,form',
|
||||
'context': {'default_project_id': self.id},
|
||||
'help': "<p class='o_view_nocontent_smiling_face'>%s</p><p>%s</p>" % (
|
||||
_("No bill of materials found. Let's create one."),
|
||||
_("Bills of materials allow you to define the list of required raw materials used to make a finished "
|
||||
"product; through a manufacturing order or a pack of products."),
|
||||
),
|
||||
}
|
||||
boms = self.env['mrp.bom'].search([('project_id', '=', self.id)])
|
||||
if not self.env.context.get('from_embedded_action', False) and len(boms) == 1:
|
||||
action['views'] = [[False, 'form']]
|
||||
action['res_id'] = boms.id
|
||||
return action
|
||||
|
||||
def action_view_mrp_production(self):
|
||||
self.ensure_one()
|
||||
action = self.env['ir.actions.actions']._for_xml_id('mrp.mrp_production_action')
|
||||
action['domain'] = [('project_id', '=', self.id)]
|
||||
action['context'] = {'default_project_id': self.id, 'from_project_action': True}
|
||||
productions = self.env['mrp.production'].search([('project_id', '=', self.id)])
|
||||
if not self.env.context.get('from_embedded_action', False) and len(productions) == 1:
|
||||
action['views'] = [[False, 'form']]
|
||||
action['res_id'] = productions.id
|
||||
return action
|
||||
|
||||
def _get_stat_buttons(self):
|
||||
buttons = super()._get_stat_buttons()
|
||||
if self.env.user.has_group('mrp.group_mrp_user'):
|
||||
buttons.extend([{
|
||||
'icon': 'flask',
|
||||
'text': self.env._('Bills of Materials'),
|
||||
'number': self.bom_count,
|
||||
'action_type': 'object',
|
||||
'action': 'action_view_mrp_bom',
|
||||
'show': self.bom_count > 0,
|
||||
'sequence': 35,
|
||||
},
|
||||
{
|
||||
'icon': 'wrench',
|
||||
'text': self.env._('Manufacturing Orders'),
|
||||
'number': self.production_count,
|
||||
'action_type': 'object',
|
||||
'action': 'action_view_mrp_production',
|
||||
'show': self.production_count > 0,
|
||||
'sequence': 46,
|
||||
}])
|
||||
return buttons
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
|
||||
def _prepare_mo_vals(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values, bom):
|
||||
res = super()._prepare_mo_vals(product_id, product_qty, product_uom, location_id, name, origin, company_id, values, bom)
|
||||
if values.get('project_id'):
|
||||
res['project_id'] = values.get('project_id')
|
||||
return res
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = 'stock.move'
|
||||
|
||||
def _prepare_procurement_values(self):
|
||||
res = super()._prepare_procurement_values()
|
||||
if res.get('group_id') and len(res['group_id'].mrp_production_ids) == 1:
|
||||
res['project_id'] = res['group_id'].mrp_production_ids.project_id.id
|
||||
return res
|
||||
Loading…
Add table
Add a link
Reference in a new issue