Skip to content

Commit

Permalink
[IMP] sale_elaboration: black, isort
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-teruel authored and Ernesto Tejeda committed Jun 1, 2023
1 parent 1b54055 commit 32d2f4d
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 170 deletions.
38 changes: 18 additions & 20 deletions sale_elaboration/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
'name': 'Sale Elaboration',
'summary': 'Set an elaboration for any sale line',
'version': '12.0.1.0.0',
'development_status': 'Production/Stable',
'category': 'Sale',
'website': 'https://github.com/OCA/sale-workflow',
'author': 'Tecnativa, Odoo Community Association (OCA)',
'license': 'AGPL-3',
'application': False,
'installable': True,
'depends': [
'sale_stock',
],
'data': [
'security/ir.model.access.csv',
'views/product_views.xml',
'views/sale_elaboration_views.xml',
'views/sale_order_views.xml',
'views/sale_elaboration_report_views.xml',
'reports/report_deliveryslip.xml',
"name": "Sale Elaboration",
"summary": "Set an elaboration for any sale line",
"version": "12.0.1.0.0",
"development_status": "Production/Stable",
"category": "Sale",
"website": "https://github.com/OCA/sale-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["sale_stock"],
"data": [
"security/ir.model.access.csv",
"views/product_views.xml",
"views/sale_elaboration_views.xml",
"views/sale_order_views.xml",
"views/sale_elaboration_report_views.xml",
"reports/report_deliveryslip.xml",
],
}
4 changes: 2 additions & 2 deletions sale_elaboration/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@


class ProductTemplate(models.Model):
_inherit = 'product.template'
_inherit = "product.template"

is_elaboration = fields.Boolean(string='Is elaboration')
is_elaboration = fields.Boolean(string="Is elaboration")
33 changes: 14 additions & 19 deletions sale_elaboration/models/product_elaboration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,41 @@


class Elaboration(models.Model):
_name = 'product.elaboration'
_description = 'Product elaborations'
_name = "product.elaboration"
_description = "Product elaborations"

name = fields.Char(
required=True,
translate=True,
)
code = fields.Char(
string='Short Code',
)
name = fields.Char(required=True, translate=True)
code = fields.Char(string="Short Code")
product_id = fields.Many2one(
comodel_name='product.product',
string='Product',
ondelete='restrict',
domain=[('type', '=', 'service'), ('is_elaboration', '=', True)],
comodel_name="product.product",
string="Product",
ondelete="restrict",
domain=[("type", "=", "service"), ("is_elaboration", "=", True)],
required=True,
)

_sql_constraints = [
('name_uniq', 'unique(name)', 'Name must be unique!'),
('code_uniq', 'unique(code)', 'Code must be unique!'),
("name_uniq", "unique(name)", "Name must be unique!"),
("code_uniq", "unique(code)", "Code must be unique!"),
]

@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
def name_search(self, name, args=None, operator="ilike", limit=100):
"""Give preference to codes on name search, appending
the rest of the results after.
"""
if not args:
args = []
recs = self.search([('code', operator, name)] + args, limit=limit)
recs = self.search([("code", operator, name)] + args, limit=limit)
res = recs.name_get()
if limit:
limit_rest = limit - len(recs)
else: # pragma: no cover
# limit can be 0 or None representing infinite
limit_rest = limit
if limit_rest or not limit:
args += [('id', 'not in', recs.ids)]
args += [("id", "not in", recs.ids)]
res += super().name_search(
name, args=args, operator=operator, limit=limit_rest,
name, args=args, operator=operator, limit=limit_rest
)
return res
47 changes: 21 additions & 26 deletions sale_elaboration/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def _execute_onchanges(records, field_name):
"""Helper methods that executes all onchanges associated to a field."""
for onchange in records._onchange_methods.get(field_name, []):
for record in records:
record._origin = record.env['sale.order.line']
record._origin = record.env["sale.order.line"]
onchange(record)


class SaleOrder(models.Model):
_inherit = 'sale.order'
_inherit = "sale.order"

def _create_elaboration_line(self, product, qty):
"""Create a sale order line from a elaboration product, search a line
Expand All @@ -22,55 +22,50 @@ def _create_elaboration_line(self, product, qty):
:param qty:
:return: the sale order line record created
"""
SaleOrderLine = self.env['sale.order.line']
sol_for_product = self.order_line.filtered(
lambda x: x.product_id == product)[:1]
SaleOrderLine = self.env["sale.order.line"]
sol_for_product = self.order_line.filtered(lambda x: x.product_id == product)[
:1
]
if sol_for_product:
sol_for_product.product_uom_qty += qty
return sol_for_product
sol = SaleOrderLine.new({
'order_id': self.id,
'product_id': product.id,
'is_elaboration': True,
})
sol = SaleOrderLine.new(
{"order_id": self.id, "product_id": product.id, "is_elaboration": True}
)
# TODO: Needed?
sol._origin = SaleOrderLine
_execute_onchanges(sol, 'product_id')
sol.update({'product_uom_qty': qty})
_execute_onchanges(sol, 'product_uom_qty')
_execute_onchanges(sol, "product_id")
sol.update({"product_uom_qty": qty})
_execute_onchanges(sol, "product_uom_qty")
vals = sol._convert_to_write(sol._cache)
if self.order_line:
vals['sequence'] = self.order_line[-1].sequence + 1
vals["sequence"] = self.order_line[-1].sequence + 1
return SaleOrderLine.sudo().create(vals)


class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
_inherit = "sale.order.line"

elaboration_id = fields.Many2one(
comodel_name='product.elaboration',
string='Elaboration',
ondelete='restrict',
comodel_name="product.elaboration", string="Elaboration", ondelete="restrict"
)
elaboration_note = fields.Char(string='Elaboration Note')
is_elaboration = fields.Boolean(string='Is Elaboration')
elaboration_note = fields.Char(string="Elaboration Note")
is_elaboration = fields.Boolean(string="Is Elaboration")
confirmation_date = fields.Datetime(
related='order_id.confirmation_date',
string='Date',
readonly=True,
related="order_id.confirmation_date", string="Date", readonly=True
)

@api.onchange('elaboration_id')
@api.onchange("elaboration_id")
def onchange_elaboration_id(self):
self.elaboration_note = self.elaboration_id.name

def _prepare_invoice_line(self, qty):
vals = super()._prepare_invoice_line(qty)
if self.is_elaboration:
vals['name'] = '{} - {}'.format(self.order_id.name, self.name)
vals["name"] = "{} - {}".format(self.order_id.name, self.name)
return vals

@api.onchange('product_id')
@api.onchange("product_id")
def product_id_change(self):
result = super().product_id_change()
self.is_elaboration = self.product_id.is_elaboration
Expand Down
9 changes: 3 additions & 6 deletions sale_elaboration/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@


class StockPicking(models.Model):
_inherit = 'stock.picking'
_inherit = "stock.picking"

def action_done(self):
res = super(StockPicking, self).action_done()
with self.env.norecompute():
for pick in self.filtered(
lambda x: x.picking_type_code == 'outgoing'
):
for pick in self.filtered(lambda x: x.picking_type_code == "outgoing"):
elaboration_lines = pick.move_lines.filtered(
lambda x: x.sale_line_id.elaboration_id
)
for line in elaboration_lines:
pick.sale_id._create_elaboration_line(
line.sale_line_id.elaboration_id.product_id,
line.quantity_done,
line.sale_line_id.elaboration_id.product_id, line.quantity_done
)
self.recompute()
return res
Loading

0 comments on commit 32d2f4d

Please sign in to comment.