Skip to content

Commit

Permalink
[MIG] purchase_landed_cost: Migration to 12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestotejeda authored and OCA-git-bot committed Aug 16, 2019
1 parent 270574a commit 33d304e
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 53 deletions.
15 changes: 8 additions & 7 deletions purchase_landed_cost/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Purchase landed costs - Alternative option
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/11.0/purchase_landed_cost
:target: https://github.com/OCA/purchase-workflow/tree/12.0/purchase_landed_cost
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-11-0/purchase-workflow-11-0-purchase_landed_cost
:target: https://translation.odoo-community.org/projects/purchase-workflow-12-0/purchase-workflow-12-0-purchase_landed_cost
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/142/11.0
:target: https://runbot.odoo-community.org/runbot/142/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -60,7 +60,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_landed_cost%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_landed_cost%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -81,8 +81,9 @@ Contributors
* Santi Argüeso <santi@comunitea.com>
* `Tecnativa <https://www.tecnativa.com>`_:

* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Pedro M. Baeza
* Vicent Cubells
* Ernesto Tejeda

Maintainers
~~~~~~~~~~~
Expand All @@ -97,6 +98,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/11.0/purchase_landed_cost>`_ project on GitHub.
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/12.0/purchase_landed_cost>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 2 additions & 3 deletions purchase_landed_cost/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
'name': 'Purchase landed costs - Alternative option',
'version': '11.0.1.0.0',
'version': '12.0.1.0.0',
"author": "AvanzOSC,"
"Tecnativa,"
"Joaquín Gutierrez,"
Expand All @@ -14,8 +14,7 @@
'website': 'https://github.com/OCA/purchase-workflow',
'summary': 'Purchase cost distribution',
'depends': [
'stock_account',
'purchase',
'purchase_stock',
],
'data': [
'data/purchase_cost_distribution_sequence.xml',
Expand Down
34 changes: 31 additions & 3 deletions purchase_landed_cost/models/purchase_cost_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def _compute_standard_price_old(self):
product_qty = fields.Float(
string='Quantity', compute='_get_product_qty', store=True)
product_uom = fields.Many2one(
comodel_name='product.uom', string='Unit of measure',
comodel_name='uom.uom', string='Unit of measure',
related='move_id.product_uom')
product_price_unit = fields.Float(
string='Unit price', related='move_id.price_unit')
Expand Down Expand Up @@ -468,6 +468,20 @@ def _compute_standard_price_old(self):
store=True,
)

@api.model
def get_action_purchase_cost_distribution(self):
xml_id = 'purchase_landed_cost.action_purchase_cost_distribution'
action = self.env.ref(xml_id).read()[0]
distributions = self.mapped('distribution')
if len(distributions) == 1:
form = self.env.ref(
'purchase_landed_cost.purchase_cost_distribution_form')
action['views'] = [(form.id, 'form')]
action['res_id'] = distributions.id
else:
action['domain'] = [('id', 'in', distributions.ids)]
return action


class PurchaseCostDistributionLineExpense(models.Model):
_name = "purchase.cost.distribution.line.expense"
Expand Down Expand Up @@ -561,13 +575,27 @@ def _compute_display_name(self):

@api.onchange('type')
def onchange_type(self):
"""set expense_amount in the currency of the distribution"""
if self.type and self.type.default_amount:
self.expense_amount = self.type.default_amount
currency_from = self.type.company_id.currency_id
amount = self.type.default_amount
currency_to = self.distribution.currency_id
company = self.company_id or self.env.user.company_id
cost_date = self.distribution.date or fields.Date.today()
self.expense_amount = currency_from._convert(amount, currency_to,
company, cost_date)

@api.onchange('invoice_line')
def onchange_invoice_line(self):
"""set expense_amount in the currency of the distribution"""
self.invoice_id = self.invoice_line.invoice_id.id
self.expense_amount = self.invoice_line.price_subtotal
currency_from = self.invoice_line.company_id.currency_id
amount = self.invoice_line.price_subtotal
currency_to = self.distribution.currency_id
company = self.company_id or self.env.user.company_id
cost_date = self.distribution.date or fields.Date.today()
self.expense_amount = currency_from._convert(amount, currency_to,
company, cost_date)

@api.multi
def button_duplicate(self):
Expand Down
16 changes: 1 addition & 15 deletions purchase_landed_cost/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,4 @@ def action_open_landed_cost(self):
line_obj = self.env['purchase.cost.distribution.line']
lines = line_obj.search([('purchase_id', '=', self.id)])
if lines:
mod_obj = self.env['ir.model.data']
model, action_id = tuple(
mod_obj.get_object_reference(
'purchase_landed_cost',
'action_purchase_cost_distribution'))
action = self.env[model].browse(action_id).read()[0]
ids = set([x.distribution.id for x in lines])
if len(ids) == 1:
res = mod_obj.get_object_reference(
'purchase_landed_cost', 'purchase_cost_distribution_form')
action['views'] = [(res and res[1] or False, 'form')]
action['res_id'] = list(ids)[0]
else:
action['domain'] = "[('id', 'in', %s)]" % list(ids)
return action
return lines.get_action_purchase_cost_distribution()
16 changes: 1 addition & 15 deletions purchase_landed_cost/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,4 @@ def action_open_landed_cost(self):
line_obj = self.env['purchase.cost.distribution.line']
lines = line_obj.search([('picking_id', '=', self.id)])
if lines:
mod_obj = self.env['ir.model.data']
model, action_id = tuple(
mod_obj.get_object_reference(
'purchase_landed_cost',
'action_purchase_cost_distribution'))
action = self.env[model].browse(action_id).read()[0]
ids = set([x.distribution.id for x in lines])
if len(ids) == 1:
res = mod_obj.get_object_reference(
'purchase_landed_cost', 'purchase_cost_distribution_form')
action['views'] = [(res and res[1] or False, 'form')]
action['res_id'] = list(ids)[0]
else:
action['domain'] = "[('id', 'in', %s)]" % list(ids)
return action
return lines.get_action_purchase_cost_distribution()
5 changes: 3 additions & 2 deletions purchase_landed_cost/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
* Santi Argüeso <santi@comunitea.com>
* `Tecnativa <https://www.tecnativa.com>`_:

* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Pedro M. Baeza
* Vicent Cubells
* Ernesto Tejeda
11 changes: 6 additions & 5 deletions purchase_landed_cost/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Purchase landed costs - Alternative option</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/11.0/purchase_landed_cost"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/purchase-workflow-11-0/purchase-workflow-11-0-purchase_landed_cost"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/142/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/12.0/purchase_landed_cost"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/purchase-workflow-12-0/purchase-workflow-12-0-purchase_landed_cost"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/142/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<div class="section" id="this-module-manages-your-purchase-expenses">
<h1>This module manages your purchase expenses</h1>
<p>The functionality of this module is to provide a way to manage your purchase
Expand Down Expand Up @@ -398,7 +398,7 @@ <h1>Bug Tracker</h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/purchase-workflow/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_landed_cost%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_landed_cost%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -417,8 +417,9 @@ <h2>Contributors</h2>
<li>Joaquín Gutierrez &lt;<a class="reference external" href="mailto:joaquing.pedrosa&#64;gmail.com">joaquing.pedrosa&#64;gmail.com</a>&gt;</li>
<li>Santi Argüeso &lt;<a class="reference external" href="mailto:santi&#64;comunitea.com">santi&#64;comunitea.com</a>&gt;</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;tecnativa.com">pedro.baeza&#64;tecnativa.com</a>&gt;</li>
<li>Vicent Cubells &lt;<a class="reference external" href="mailto:vicent.cubells&#64;tecnativa.com">vicent.cubells&#64;tecnativa.com</a>&gt;</li>
<li>Pedro M. Baeza</li>
<li>Vicent Cubells</li>
<li>Ernesto Tejeda</li>
</ul>
</li>
</ul>
Expand All @@ -430,7 +431,7 @@ <h2>Maintainers</h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/11.0/purchase_landed_cost">OCA/purchase-workflow</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/12.0/purchase_landed_cost">OCA/purchase-workflow</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<sheet>
<div class="oe_title">
<h1>
<label string="Cost distribution "/>
<label for="name" string="Cost distribution "/>
<field name="name" class="oe_inline" readonly="1"/>
</h1>
</div>
Expand Down
13 changes: 11 additions & 2 deletions purchase_landed_cost/wizard/import_invoice_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ class ImportInvoiceLine(models.TransientModel):
@api.multi
def action_import_invoice_line(self):
self.ensure_one()
dist_id = self.env.context['active_id']
distribution = self.env['purchase.cost.distribution'].browse(dist_id)
currency_from = self.invoice_line.company_id.currency_id
amount = self.invoice_line.price_subtotal
currency_to = distribution.currency_id
company = distribution.company_id or self.env.user.company_id
cost_date = distribution.date or fields.Date.today()
expense_amount = currency_from._convert(amount, currency_to, company,
cost_date)
self.env['purchase.cost.distribution.expense'].create({
'distribution': self.env.context['active_id'],
'distribution': dist_id,
'invoice_line': self.invoice_line.id,
'invoice_id': self.invoice_line.invoice_id.id,
'ref': self.invoice_line.name,
'expense_amount': self.invoice_line.price_subtotal,
'expense_amount': expense_amount,
'type': self.expense_type.id,
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class ImportLandedCostPickingsWizard(models.TransientModel):
_name = 'import.landed.cost.pickings.wizard'
_description = 'Import landed cost pickings'

possible_picking_ids = fields.Many2many(
comodel_name="stock.picking", string="Possible pickings")
Expand Down

0 comments on commit 33d304e

Please sign in to comment.