Skip to content

Commit

Permalink
[REF] mrp_production_batch: commit reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankC013 committed Feb 1, 2024
1 parent 58583ad commit 0b8a31b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 52 deletions.
45 changes: 22 additions & 23 deletions mrp_production_batch/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def mrp_production_batch_create_wizard_action(self):
def _action_generate_consumption_wizard(self, consumption_issues):
if not self.env.context.get("mrp_production_batch_create"):
return super()._action_generate_consumption_wizard(consumption_issues)

Check warning on line 159 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L159

Added line #L159 was not covered by tests
if self.bom_id.bom_line_ids.product_id.ids != self.move_raw_ids.product_id.ids:
if self.bom_id.bom_line_ids.product_id != self.move_raw_ids.product_id:
raise ValidationError(

Check warning on line 161 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L161

Added line #L161 was not covered by tests
_(
"A problem has been detected in production %s. Make sure you "
Expand Down Expand Up @@ -200,28 +200,27 @@ def action_view_production_batch(self):
"res_id": self.production_batch_id.id,
}

# TODO: Refactor translation management and raise of "You need to supply..."
def action_check_with_batch(self):
self.ensure_one()
try:
with self.env.cr.savepoint():
self_wc = self.with_context(mrp_production_batch_create=True)
lot = self_wc.env["stock.production.lot"].create(
{
"name": "",
"product_id": self.product_id.id,
"company_id": self.company_id.id,
}
)
self_wc.lot_producing_id = lot.id
self_wc.button_mark_done()
raise FakeException("")
except FakeException:
self.is_ready_to_produce = True
self.error_message = False
except (UserError, ValidationError) as e:
self.is_ready_to_produce = False
self.error_message = e.name
def action_produce_batch(self):
for rec in self:
try:
with rec.env.cr.savepoint():
self_wc = rec.with_context(mrp_production_batch_create=True)
lot = self_wc.env["stock.production.lot"].create(

Check warning on line 208 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L205-L208

Added lines #L205 - L208 were not covered by tests
{
"name": "",
"product_id": rec.product_id.id,
"company_id": rec.company_id.id,
}
)
self_wc.lot_producing_id = lot.id
self_wc.button_mark_done()
raise FakeException("")

Check warning on line 217 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L215-L217

Added lines #L215 - L217 were not covered by tests
except FakeException:
rec.is_ready_to_produce = True
rec.error_message = False
except (UserError, ValidationError) as e:
rec.is_ready_to_produce = False
rec.error_message = e.name

Check warning on line 223 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L219-L223

Added lines #L219 - L223 were not covered by tests

def create_batch_lot_by_bom(self):
self.ensure_one()

Check warning on line 226 in mrp_production_batch/models/mrp_production.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production.py#L226

Added line #L226 was not covered by tests
Expand Down
44 changes: 16 additions & 28 deletions mrp_production_batch/models/mrp_production_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ def action_check(self):
self.ensure_one()

Check warning on line 125 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L125

Added line #L125 was not covered by tests
productions = self.production_ids.filtered(lambda r: not r.is_ready_to_produce)
init_production_count = len(productions)
for production in productions:
production.action_check_with_batch()
productions.action_produce_batch()

Check warning on line 128 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L127-L128

Added lines #L127 - L128 were not covered by tests
final_production_count = len(
self.production_ids.filtered(lambda r: not r.is_ready_to_produce)
)
Expand All @@ -139,31 +138,24 @@ def action_check(self):

def _check_unique_serial_lot_in_batch(self):
for rec in self:
serial_lots = []
lots_dups = set()

Check warning on line 141 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L141

Added line #L141 was not covered by tests
for production in rec.production_ids:
serial_move_line = production.move_raw_ids.filtered(
lambda x: x.product_id.tracking == "serial"
).move_line_ids
serial_lot_ids = serial_move_line.mapped("lot_id").ids
serial_lots.extend(serial_lot_ids)
for lot in serial_lots:
if serial_lots.count(lot) > 1:
move = (
self.env["stock.move.line"]
.search([("lot_id", "=", lot)])
.filtered(
lambda x: x.move_id.raw_material_production_id
in rec.production_ids
)
.move_id
lots = set(
production.move_raw_ids.filtered(
lambda x: x.product_id.tracking == "serial"
)
.move_line_ids.mapped("lot_id")
.ids
)
if lots_dups & lots:
raise ValidationError(

Check warning on line 151 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L151

Added line #L151 was not covered by tests
_(
"The following productions are using the same serial number in"
" some of their components: %s"
% move.mapped("raw_material_production_id.display_name")
"The following production %s is using a component that "
"repeats the serial number in some other production"
% production.display_name
)
)
lots_dups |= set(lots)

Check warning on line 158 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L158

Added line #L158 was not covered by tests

def action_done(self):
self.ensure_one()
Expand Down Expand Up @@ -205,7 +197,7 @@ def action_view_production_ready(self):
action["domain"] = [("id", "in", self.ready_production_ids.ids)]
return action

Check warning on line 198 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L195-L198

Added lines #L195 - L198 were not covered by tests

def get_user_timezone_datetime(self):
def get_user_locale_tz_datetime_string(self, date):
self.ensure_one()
lang = self.env["res.lang"].search([("code", "=", self.env.user.lang)])

Check warning on line 202 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L201-L202

Added lines #L201 - L202 were not covered by tests
datetime_format = " ".join(
Expand All @@ -217,19 +209,15 @@ def get_user_timezone_datetime(self):
),
)
)
timezone = self._context.get("tz") or self.env.user.partner_id.tz or "UTC"
self_tz = self.with_context(tz=timezone)
return fields.Datetime.context_timestamp(
self_tz, fields.Datetime.from_string(self.create_date)
).strftime(datetime_format)
return fields.Datetime.context_timestamp(self, date).strftime(datetime_format)

Check warning on line 212 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L212

Added line #L212 was not covered by tests

@api.depends("name", "state")
def name_get(self):
result = []

Check warning on line 216 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L216

Added line #L216 was not covered by tests
for rec in self:
if rec.state == "draft":
state = _("Draft")
user_datetime = rec.get_user_timezone_datetime()
user_datetime = rec.get_user_locale_tz_datetime_string(rec.create_date)
name = "%s [%s] %s" % (

Check warning on line 221 in mrp_production_batch/models/mrp_production_batch.py

View check run for this annotation

Codecov / codecov/patch

mrp_production_batch/models/mrp_production_batch.py#L219-L221

Added lines #L219 - L221 were not covered by tests
state,
user_datetime,
Expand Down
2 changes: 1 addition & 1 deletion mrp_production_batch/views/mrp_production_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</xpath>
<field name="confirm_cancel" position="before">
<button
name="action_check_with_batch"
name="action_produce_batch"
type="object"
string="Check Production"
class="oe_highlight"
Expand Down

0 comments on commit 0b8a31b

Please sign in to comment.