Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] mrp_production_batch: new module #338

Open
wants to merge 21 commits into
base: 14.0
Choose a base branch
from

Conversation

KNVx
Copy link
Contributor

@KNVx KNVx commented Nov 17, 2023

No description provided.

<field name="code">mrp.production.batch</field>
<field name="prefix">MOB/</field>
<field name="padding">5</field>
<field name="company_id" eval="False" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No company??

production_batch_id = fields.Many2one(
comodel_name="mrp.production.batch",
string="Production Batch",
readonly=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ondelete attribute

def _check_production_to_batch_consitency(self, mrp_production_ids):
if not mrp_production_ids:
raise ValidationError(_("No productions selected"))
if mrp_production_ids.mapped("production_batch_id"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just if mrp_productions.production_batch_id, not needed in 14.0

raise ValidationError(
_("Some of the selected productions are already done or cancelled")
)
picking_type_ids = mrp_production_ids.mapped("picking_type_id")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

picking_types = mrp_production_ids.picking_type_id

readonly=True,
)

def _check_production_to_batch_consitency(self, mrp_production_ids):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remember the guidelines + typo: consistency

def _check_production_to_batch_consistency(self, mrp_productions):

manufacturing_ids = fields.One2many(
comodel_name="mrp.production.batch.line.wizard",
inverse_name="mrp_production_batch_id",
readonly=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is already readonly=False by default

Comment on lines 27 to 28
for production in self.manufacturing_ids:
production.production_batch_id = res.id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not be necessary

_name = "mrp.production.batch.line.wizard"
_description = "MRP Production Line Batch wizard"

mrp_production_batch_id = fields.Many2one(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to production_batch_wizard_id

Comment on lines 1 to 2
from . import wizard_mrp_production_batch
from . import wizard_mrp_production_batch_line
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check OCA guidelines if this is the way to name wizards and also check the wizard filenames



class PickingType(models.Model):
_inherit = "stock.picking.type"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This model is not stock.picking it should be in a separate file stock_picking_type. We use OCA guidelines not the Odoo ones...

Copy link

codecov bot commented Nov 21, 2023

Codecov Report

Attention: Patch coverage is 36.19048% with 201 lines in your changes are missing coverage. Please review.

Project coverage is 44.76%. Comparing base (5dd2c64) to head (06db74e).
Report is 29 commits behind head on 14.0.

Files Patch % Lines
mrp_production_batch/models/mrp_production.py 20.75% 84 Missing ⚠️
...rp_production_batch/models/mrp_production_batch.py 31.48% 73 Missing and 1 partial ⚠️
mrp_production_batch/models/stock_picking_type.py 30.95% 29 Missing ⚠️
...uction_batch/wizard/mrp_production_batch_wizard.py 50.00% 8 Missing ⚠️
mrp_production_batch/models/mrp_bom_line.py 66.66% 3 Missing ⚠️
...rp_production_batch/models/stock_production_lot.py 62.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             14.0     #338      +/-   ##
==========================================
- Coverage   44.98%   44.76%   -0.23%     
==========================================
  Files         747      759      +12     
  Lines       12972    13313     +341     
  Branches     2836     2924      +88     
==========================================
+ Hits         5835     5959     +124     
- Misses       7005     7221     +216     
- Partials      132      133       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

mrp_production_batch/__manifest__.py Outdated Show resolved Hide resolved
mrp_production_batch/__manifest__.py Outdated Show resolved Hide resolved
mrp_production_batch/__manifest__.py Outdated Show resolved Hide resolved
mrp_production_batch/models/mrp_production.py Outdated Show resolved Hide resolved
mrp_production_batch/models/mrp_production.py Outdated Show resolved Hide resolved
mrp_production_batch/models/mrp_production_batch.py Outdated Show resolved Hide resolved
).button_mark_done()
except Exception:
productions_display_name.append(production.display_name)
if productions_display_name and len(productions_display_name) == len_production:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing this len(productions_display_name) == len_production

Comment on lines 187 to 190
def action_generate_serial(self):
for rec in self:
for production in rec.production_wo_lot_producing_id:
production.action_generate_serial()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to change this, the serial numbers should be generated at the time the MO is processed.

mrp_production_batch/models/stock_move.py Outdated Show resolved Hide resolved
mrp_production_batch/readme/CONTRIBUTORS.rst Show resolved Hide resolved
Copy link
Member

@eantones eantones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Member

@eantones eantones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally:

  • def action_generate_serial(self): this shouldn't be done in a separate step, this should be done seamlessly on process batch.
  • Do an additional check on process batch. Just in case someone has changed something on a already marked "ready to process" production.

from odoo.exceptions import ValidationError


class MrpProduction(models.Model):
_inherit = "mrp.production"

is_ready_to_produce = fields.Boolean(
store=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default, you don't need to specify this, please remove it

% rec.production_batch_id.name
)
elif rec.state == "done":
if not self.env.context.get("mrp_production_batch_create"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency if mrp_production_batch_create is a boolean
if not self.env.context.get("mrp_production_batch_create", False):

Comment on lines 150 to 152
message = "The following productions could not be marked as 'done':\n"
message += "\n".join(productions_not_ready)
raise UserError(message)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message_l = [
    "The following productions could not be marked as 'done':",
    "\n".join(productions_not_ready)
]
raise UserError("\n".join(message_l))

message = "The following productions could not be marked as 'done':\n"
message += "\n".join(productions_display_name)
raise UserError(message)
with self.env.cr.savepoint():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Environment as we discussed

).button_mark_done()
raise ValidationError(raise_msg)
except (ValidationError, UserError) as e:
production.is_ready_to_produce = bool(e.name == raise_msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This willl be removed using the Environemtn approach

production.error_message = e.name
else:
production.error_message = False
if not self.env.context.get("mrp_production_check"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not self.env.context.get("mrp_production_check", False):

productions = self.production_ids.filtered(
lambda r: r.state not in ("cancel", "done")
)
productions = self.production_ids.filtered(lambda r: r.state != "cancel")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Process all productions here and check before if all of them are in "ready" state

Copy link
Member

@eantones eantones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thanks!

mrp_production_batch/i18n/es.po Outdated Show resolved Hide resolved
@eantones eantones removed the to review label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants