Skip to content
GitLab
  • Menu
    • Projects Groups Snippets
      Help
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • O odoo
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Metrics
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • rex wu
  • odoo
  • Merge requests
  • !27

feat(xlsx): add bom export function

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged rex wu requested to merge 15.0 into deploy 1 year ago
  • Overview 0
  • Commits 9
  • Changes 23

Introduce webcontroller to handle http request. Breaking export function of purchase and it will be fixed in next commit.

  • rex wu @rexwu assigned to @rexwu 1 year ago

    assigned to @rexwu

  • rex wu @rexwu mentioned in commit 8b5d11cd 1 year ago

    mentioned in commit 8b5d11cd

  • rex wu @rexwu merged 1 year ago

    merged

  • Loading
  • Loading
  • You're only seeing other activity in the feed. To add a comment, switch to one of the following options.
Please register or sign in to reply
Compare
  • deploy (base)

and
  • latest version
    1642a3ec
    9 commits, 1 year ago

23 files
+ 448
- 11

    Preferences

    File browser
    Compare changes
extra-‎addons‎
kci‎-mrp‎
contr‎ollers‎
__ini‎t__.py‎ +1 -0
contro‎ller.py‎ +62 -0
mod‎els‎
mrp_b‎om.py‎ +19 -5
vi‎ews‎
mrp_bom_‎views.xml‎ +15 -2
__ini‎t__.py‎ +2 -1
kci-pu‎rchase‎
contr‎ollers‎
__ini‎t__.py‎ +1 -0
contro‎ller.py‎ +30 -0
mod‎els‎
internal_p‎urchase.py‎ +1 -1
purch‎ase.py‎ +1 -0
vi‎ews‎
purchase_‎views.xml‎ +3 -0
__ini‎t__.py‎ +2 -1
kci-repor‎t-template‎
sta‎tic‎
src‎/js‎
repo‎rt.js‎ +223 -0
xlsx-popul‎ate.min.js‎ +2 -0
xl‎sx‎
bom1‎.xlsx‎ +0 -0
bom2‎.xlsx‎ +0 -0
purcha‎se.xlsx‎ +0 -0
quotati‎on.xlsx‎ +0 -0
__manif‎est__.py‎ +5 -0
sa‎les‎
contr‎ollers‎
__ini‎t__.py‎ +1 -0
contro‎ller.py‎ +28 -0
mod‎els‎
sale_orde‎r_model.py‎ +47 -0
vi‎ews‎
view‎s.xml‎ +3 -0
__ini‎t__.py‎ +2 -1
extra-addons/kci-mrp/controllers/__init__.py 0 → 100644
+ 1
- 0
  • View file @ 1642a3ec

  • Edit in single-file editor

  • Open in Web IDE

from . import controller
\ No newline at end of file
extra-addons/kci-mrp/controllers/controller.py
+ 62
- 0
  • View file @ 1642a3ec

  • Edit in single-file editor

  • Open in Web IDE

import json
from odoo import http
class MrpBomDump(http.Controller):
@http.route('/mrp/bom/dump', type='http', auth='user')
def index(self, **kw):
bom = http.request.env['mrp.bom'].search([('id', '=', kw.get('id'))])
if bom.status == 'external':
return self.bom2(**kw)
elif bom.status == 'internal':
return self.bom1(**kw)
return ''
def bom1(self, **kw):
res = {}
bom = http.request.env['mrp.bom'].search([('id', '=', kw.get('id'))])
res["bom_status"] = bom.status
res["project"] = bom.project_id.name
res["inquiry_code"] = bom.inquiry_id.code
res["date"] = str(bom.date)
res["engineer"] = bom.user_id.name
res["bom_lines"] = []
for line in bom.bom_line_ids:
res["bom_lines"].append({
"product": line.product_id.name,
"qty": line.product_qty,
"price": line.price_unit,
})
return json.dumps(res)
def bom2(self, **kw):
res = {}
bom = http.request.env['mrp.bom'].search([('id', '=', kw.get('id'))])
inquiry = bom.inquiry_id
res['bom_status'] = bom.status
res['order_code'] = inquiry.code
res['name'] = bom.product_tmpl_id.name
res['customer'] = bom.customer_id.name
res['date'] = str(bom.date)
res['engineer'] = bom.user_id.name
res['bom_lines'] = []
for line in bom.bom_line_ids:
suppliers = []
purchase = (line.material_source == 'stock' and line.product_id.qty_available < line.product_qty) or line.material_source == 'purchase'
for supplier in sorted(line.product_id.seller_ids, key=lambda s:s['price'])[:3]:
suppliers.append({
'name': supplier.name.name,
'price': supplier.price,
#'currency': supplier.currency_id.name,
'moq': supplier.min_qty,
'lead_time': supplier.delay,
})
res['bom_lines'].append({
'purchase': purchase,
'product': line.product_id.name,
'qty': line.product_qty,
'suppliers': suppliers,
'best_supplier': min(suppliers, key=lambda s: s['price']) if len(suppliers) else ''
})
return json.dumps(res)
extra-addons/kci-mrp/models/mrp_bom.py
+ 19
- 5
  • View file @ 1642a3ec

  • Edit in single-file editor

  • Open in Web IDE


@@ -120,21 +120,21 @@ class Bom(models.Model):
mail_template = self.env.ref('kci-mrp.bom_email_template')
mail_template.send_mail(self.id, force_send=True, email_values=email_values)
@api.depends('bom_line_ids.price')
@api.depends('bom_line_ids.price_subtotal')
def _compute_total(self):
for bom in self:
amount = 0.0
for line in bom.bom_line_ids:
amount += line.price
amount += line.price_subtotal
bom.update({
'amount_total': amount,
})
@api.depends('bom_line_ids.quotation_price')
@api.depends('bom_line_ids.quotation_price', 'bom_line_ids.product_qty')
def _compute_quotation(self):
for bom in self:
bom.update({
'quotation_total': sum(line.quotation_price for line in bom.bom_line_ids),
'quotation_total': sum(line.quotation_price * line.product_qty for line in bom.bom_line_ids),
})
@@ -145,14 +145,28 @@ class BomLine(models.Model):
'mrp.bom', 'Parent BoM',
index=True, ondelete='cascade', required=True)
price = fields.Float(string='價格', store=True)
price_unit = fields.Float(string='單價', store=True)
price_subtotal = fields.Float(string='小計', store=True, compute='_compute_price_subtotal')
quotation_price = fields.Float(string='報價', store=True)
quotation_name = fields.Char(string='報價名稱')
quotation_subtotal = fields.Float(string='報價小計', store=True, compute='_compute_quotation_subtotal')
qty_available = fields.Float(string='庫存數量', related='product_id.qty_available', store=True)
product_type = fields.Selection(related='product_tmpl_id.type', string='產品類型', store=True)
material_source = fields.Selection([
('purchase', '採購'),
('stock', '庫存')
], string='來源', default='stock')
@api.depends('quotation_price', 'product_qty')
def _compute_quotation_subtotal(self):
for line in self:
line.quotation_subtotal = line.quotation_price * line.product_qty
@api.depends('product_qty', 'price_unit')
def _compute_price_subtotal(self):
for line in self:
line.price_subtotal = line.product_qty * line.price_unit
# class InternalBom(models.Model):
# _name = "mrp.internal.bom"
extra-addons/kci-mrp/views/mrp_bom_views.xml
+ 15
- 2
  • View file @ 1642a3ec

  • Edit in single-file editor

  • Open in Web IDE


@@ -5,6 +5,12 @@
<field name="model">mrp.bom</field>
<field name="inherit_id" ref="mrp.mrp_bom_form_view"/>
<field name="arch" type="xml">
<xpath expr="//sheet" position="before">
<header>
<button string="匯出成 Xlsx" class="oe_highlight" id="report_xlsx"/>
</header>
</xpath>
<xpath expr="//div[@name='button_box']" position="inside">
<button name="action_bom1_to_quotation" action="action_bom1_to_quotation" string="產生報價 BOM 表" type="object" icon="fa-file" class="oe_stat_button" attrs="{'invisible': [('status', '!=', 'internal')]}"/>
<button name="action_create_quotation" action="action_create_quotation" string="產生報價單" type="object" icon="fa-dollar" class="oe_stat_button" attrs="{'invisible': [('status', '!=', 'quotation')]}"/>
@@ -25,10 +31,17 @@
<field name="quotation_name" attrs="{'column_invisible': [('parent.status', '!=', 'quotation')]}"/>
</xpath>
<xpath expr="//field/tree/field[@name='operation_id']" position="after">
<xpath expr="//field/tree/field[@name='product_qty']" position="before">
<field name="material_source" attrs="{'column_invisible': [('parent.status', '!=', 'external')]}"/>
<field name="price" attrs="{'column_invisible': [('parent.status', '=', 'external')]}"/>
<field name="product_type"/>
</xpath>
<xpath expr="//field/tree/field[@name='operation_id']" position="after">
<!-- Only product will show available qty -->
<field name="qty_available" attrs="{'invisible': [('product_type', '!=', 'product')]}"/>
<field name="price_unit" attrs="{'column_invisible': [('parent.status', '=', 'external')]}"/>
<field name="price_subtotal" attrs="{'column_invisible': [('parent.status', '=', 'external')]}"/>
<field name="quotation_price" attrs="{'column_invisible': [('parent.status', '!=', 'quotation')]}"/>
<field name="quotation_subtotal" attrs="{'column_invisible': [('parent.status', '!=', 'quotation')]}"/>
</xpath>
<xpath expr="//field[@name='company_id']" position="after">
extra-addons/kci-mrp/__init__.py
+ 2
- 1
  • View file @ 1642a3ec

  • Edit in single-file editor

  • Open in Web IDE

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
\ No newline at end of file
from . import models
from . import controllers
\ No newline at end of file
Assignee
rex wu's avatar
rex wu
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
rex wu
Reference: rexwu/odoo!27
Source branch: 15.0

Menu

Projects Groups Snippets
Help